[scribus] Script: Adjust frame to image
Gregory Pittman
gpittman at iglou.com
Tue Jun 26 02:22:15 UTC 2012
On 06/25/2012 12:54 PM, Stefano Danzi wrote:
>
> Hello!! I'm resurrecting an old post ...
>
>
>
> I need to adapt my old scripts for new versions of Scribus and are
> all based on this code ... :'( Someone could help me?
>
Hi Stefano,
your message prompted me to revisit an old problem I had when I
enhanced the InfoBox.py script. In what I thought was its best
incarnation, it made use of the Python Imaging Library (PIL) to get
the dimensions of an image in order to scale the frame size.
At some point, it no longer worked to import this library -- the
script would hang -- so I took that out and ended up with the much
less elegant way it works now, where you need to manually run Adjust
Frame to Image after the script ran.
I pulled out one of my old versions using PIL and now it WORKS!!
As soon as I get it polished up, I'll replace InfoBox.py with this PIL
version for svn. In the meantime, here are some pointers:
put this at the top of your script;
try:
from PIL import Image
except ImportError:
print "Unable to import the Python Imaging Library module."
sys.exit(1)
Here is how I used the module. After using a file dialog to get an
image file name (variable name imageload):
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)
The first two lines are functions from PIL, with the plan to get the
dimensions of the actual image. In InfoBox, we are creating a frame to
fill the width of one or more columns of a text frame, so the width is
fixed, and we just need to calculate the correct height and make the
frame, load the image.
After this, then later was the line:
scribus.setScaleImageToFrame(1,1,new_image)
to scale to your exactly right frame size.
For your uses, the calculations may be different, of course, depending
on whether you adjust width, height, or both. In a sense here you are
adjusting the frame to the image before you even load the image.
Greg
More information about the scribus
mailing list