[scribus] Scribus 1.3.5.1: Adjust Frame to Image script

Gregory Pittman gregp_ky at yahoo.com
Fri Sep 18 01:47:45 CEST 2009


On 09/17/2009 06:17 PM, a.l.e wrote:
> ciao stefano,
>
>   Since Scribus 1.3.3.13 I use code above to do "Adjust Frame to Image"
>    
>> in my scripts. On Scribus 1.3.5.1 this don't work...
>>
>> Somaine has found a solution????
>>
>> ---------------------------------------
>>
>> ## 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 )
>>      
> it somehow works in 1.5 (as already reported by matis you have to use getUnit and setUnit)...
>
> still it doesn't really adjust the frame to the image... i'm looking at those lines
>
>    
>> imageW = frameW * (saveScaleX / fullScaleX)
>> imageH = frameH * (saveScaleY / fullScaleY)
>>      
> and try to figure out which computation will also adjust the non fitting frame!
>    
if you look here:

http://wiki.scribus.net/index.php/Infobox_in_column

you can review this script, which was made to insert a frame in a column 
of text, the exact width of the column. There was a kludgy sort of way 
that compensated for the lack of Adjust Frame to image, but what I 
eventually did is what you see below in this code fragment. The basic 
idea is to start with a certain width of the frame, then use the PIL 
(Python imaging library) to assess the size of the image and calculate 
an appropriate size for the frame.

         if (frametype == 'imageL'):
	    imageload = scribus.fileDialog('Load image','Images(*.jpg *.png *.tif *.JPG *.PNG *.jpeg *.JPEG *.TIF)',haspreview=1)
             im = Image.open(imageload)
             xsize, ysize = im.size
	    new_height = float(ysize)/float(xsize)*new_width
	    new_image = scribus.createImage(new_left, float(new_top), new_width, float(new_height),framename)
	    scribus.loadImage(imageload, new_image)


Greg




More information about the scribus mailing list