[scribus] Scribus 1.3.5.1: Adjust Frame to Image script

a.l.e ale.comp_06 at xox.ch
Fri Sep 18 01:02:46 CEST 2009


ciao stefano,

> > ## Adjust Frame to Image
> > ## First select the frame of the image
> > saveUnit = setUnit(UNIT_POINTS)
> > obj = getSelectedObject()
> > 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)
> > sizeObject( imageW, imageH, obj )
> > setUnit( saveUnit )


simplified to the bone...

---- 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 ----

tested with 1.5svn and i hope will work with 1.3.x, too (i don't see any reason why it shouldn't)

have fun
a.l.e



p.s.: may i ask you where did you find the parameters for getProperty()? ... it would be interesting to know if they all have an official getter/setter!




More information about the scribus mailing list