[scribus] Script: Adjust frame to image

Stefano Danzi s.danzi at hawai.it
Mon Jun 25 16:54:53 UTC 2012


Hello!!
I'm resurrecting an old post ...

I need to do the same thing of menu "Adjust frame to image" into a script...

Since Scribus 1.3.3.14 Following code work fine:

## Adjust Frame to Image
## First select the frame of the image
       frameW = getProperty(obj, "width")
       frameH = getProperty(obj, "height")
       saveScaleX = getProperty(obj, "imageXScale")
       saveScaleY = getProperty(obj, "imageYScale")
       setScaleImageToFrame(True, False, obj)
       fullScaleX = getProperty(obj, "imageXScale")
       fullScaleY = getProperty(obj, "imageYScale")
       setScaleImageToFrame(False, False, obj)
       scaleImage(saveScaleX, saveScaleY, obj)
       imageW = frameW * (saveScaleX / fullScaleX)
       imageH = frameH * (saveScaleY / fullScaleY)
       sizeObject( imageW, imageH, obj )


On newest versions this code  doesn't  work.

a.l.e. adapted the code as below, but in version 1.4.1 don't work (or 
work sometimes):

---- 8< ----
## Adjust Frame to Image
## an image frame should already be selected
##
## - save the units
## - get the object
## - get the current frame size
## - scale non proportional
## - get the x/y scales
## - get the minimum between the x and y scale (it will be kept as is when scaling proportionally)
## - modify the frame size proportionally to the rapport between the minimum scale and each axis scale (will be 1 for the limiting axis)
## - scale proportional
## - set free scaling (this step is not needed but was in your original code)

import scribus

saveUnit = scribus.getUnit()
scribus.setUnit(scribus.UNIT_POINTS)

obj = scribus.getSelectedObject()

(fW, fH) = scribus.getSize(obj)

scribus.setScaleImageToFrame(True, False, obj)
(sX, sY) = scribus.getImageScale(obj)
s = min(sX, sY);
scribus.sizeObject(fW * (s/sX), fH * (s/sY), obj)

scribus.setScaleImageToFrame(True, True, obj)
scribus.setScaleImageToFrame(False, False, obj)


scribus.setUnit(saveUnit)
---- >8 ----


I need to adapt my old scripts for new versions of Scribus and are all 
based on this code ... :'(
Someone could help me?

Message for developers: ...could you export "AdjustFrameToImage" on 
scripter API?







More information about the scribus mailing list