From 2bafb6b5a4bc40b30925b9df284bcc8e51a447fa Mon Sep 17 00:00:00 2001 From: gpittman Date: Tue, 26 Jun 2012 02:49:31 +0000 Subject: improved InfoBox.py using PIL git-svn-id: svn://scribus.net/branches/Version14x/Scribus@17637 11d20701-8431-0410-a711-e3c959e3b870 --- scribus/plugins/scriptplugin/scripts/InfoBox.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/scribus/plugins/scriptplugin/scripts/InfoBox.py b/scribus/plugins/scriptplugin/scripts/InfoBox.py index f1050e1..1353cc9 100644 --- a/scribus/plugins/scriptplugin/scripts/InfoBox.py +++ b/scribus/plugins/scriptplugin/scripts/InfoBox.py @@ -20,10 +20,10 @@ """ + (C) 2005 by Thomas R. Koll, , http://verlag.tomk32.de -(c) 2008, 2010 modifications, additional features, and some repair - by Gregory Pittman +(c) 2008, 2010, 2012 modifications, additional features, and reversion back to using PIL again! by Gregory Pittman A simple script for exact placement of a frame (infobox) over the current textbox, asking the user for the width @@ -44,6 +44,8 @@ an image. * Infobox has Text Flows Around Frame activated, also Scale Image to Frame for images. +* If you load an image with the script, an exactly correct frame height is made. + USAGE Select a textframe, start the script and have phun @@ -59,6 +61,11 @@ except ImportError: print "Unable to import the 'scribus' module. This script will only run within" print "the Python interpreter embedded in Scribus. Try Script->Execute Script." sys.exit(1) +try: + from PIL import Image +except ImportError: + print "Unable to import the Python Imaging Library module." + sys.exit(1) def main(argv): unit = scribus.getUnit() @@ -136,13 +143,16 @@ def main(argv): else: 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) - scribus.messageBox('Please Note',"Your frame will be created once you click OK.\n\nUse the Context Menu to Adjust Frame to Image.\n\nIf your image does not fill the width completely,\nstretch the frame vertically first.",scribus.BUTTON_OK) else: new_image = scribus.createImage(new_left, float(new_top), new_width, float(new_height),framename) scribus.textFlowMode(new_image, 1) - scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=new_image) + scribus.setScaleImageToFrame(1,1,new_image) +# scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=new_image) if __name__ == '__main__': # This script makes no sense without a document open if not scribus.haveDoc(): -- cgit