Automatic import of images: Versions not requiring Tkinter

scribalbum_letter.py
Link to: Automatic import of images from a directory using a script

I've reworked scribalbum.py to avoid the need for Tkinter, instead using valueDialog for entries. You will see two of these, the first for entry of the directory to be searched, the second to choose image file types. Since the Scripter API does not yet have something like checkboxes, the most intuitive way I could think of was to use letter mnemonics, j = jpg, t = tif and so on, in Python using a dictionary approach. In this version I have deleted SVGs, since these do not import into image frames. Uppercase equivalents (.JPG, .TIF, etc) will now be detected.

This latest version (as of 2008.07.23) includes a GUI requester for the directory name. In addition, you now will have a choice of either 4 or 6 pictures per page. I also cleaned up the code a bit to make it less repetitive, and changed the way pictures load into the page -- instead of loading the left column, then the right, images are loaded L-R-L-R... down the page.

Some rewriting was done so that this works with Scribus version 1.3.5svn, and the default font was changed to DejaVu Sans – if you want to use a different one, look for the labelFont variable assignment. This version of scribalbum_letter also works with Scribus 1.3.3.x.


 * 1) !/usr/bin/env python

""" This is scribalbum_letter.py. This script will load the images from a directory, creating a new document of US Letter size.

USAGE: It is probably better not to already have any document in Scribus, since memory usage can become intense when a large number of images is used. You are first presented with a dialog to choose either 4 or 6 images per page. Next select a directory where your images are located. Finally, select the types of image files, using the code you see in the last dialog. NOTE: If you choose PDF, only the first page will be imported, and the PDF will be rasterized.

AUTHOR: Gregory Pittman Original version: 2005.02.13, this version: 2008.07.23

LICENSE: This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

"""

import scribus import os

filetype = [] dicttype = {'j':'.jpg','p':'.png','t':'.tif','g':'.gif','P':'.pdf'} Dicttype = {'j':'.JPG','p':'.PNG','t':'.TIF','g':'.GIF','P':'.PDF'} nrimages = '0' while (nrimages != '4') and (nrimages != '6'): nrimages = scribus.valueDialog('Pictures','- US Letter Paper -\n Four or Six Images per Page?\nChange to 6 as desired','4') imagedir = scribus.fileDialog('Select Image Directory','Directories',isdir=True) imagetype = scribus.valueDialog('Image Types','Enter the Image Types, where\n j=jpg,p=png,t=tif,g=gif,P=pdf\n "jptgP" selects all','jptgP') for t in imagetype[0:]: filetype.append(dicttype[t]) filetype.append(Dicttype[t]) d = os.listdir(imagedir) D = [] for file in d:   for format in filetype: if file.endswith(format): D.append(file) D.sort labelFont="DejaVu Sans Book"

if nrimages == '4': xpos = [15, 310, 15, 310] ypos = [42, 187, 388, 533] if nrimages == '6': xpos = [15, 310, 15, 310, 15, 310] ypos = [42, 42, 290, 290, 533, 533] pwidth = 288 pheight = 193 imagecount = 0 if len(D) > 0: if scribus.newDoc(scribus.PAPER_LETTER, (10,10,20,20),scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.NOFACINGPAGES, scribus.FIRSTPAGERIGHT): while imagecount < len(D): if imagecount > 0: scribus.newPage(-1) framecount = 0 L = scribus.createText(15, 20, 200, 20) scribus.setText("Dir: " + imagedir, L)           scribus.setTextAlignment(scribus.ALIGN_LEFT, L)            scribus.setFont(labelFont, L)            scribus.setFontSize(10, L)            for x,y in zip(xpos,ypos): if imagecount < len(D): f = scribus.createImage(x, y, pwidth, pheight) scribus.loadImage(imagedir + '/' + D[imagecount], f)                   scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=f) lenfilename = len(D[imagecount]) Lpiclen = int(5.3 * lenfilename) Lpic = scribus.createText(x, y + 193, Lpiclen, 15) scribus.setText(D[imagecount], Lpic) scribus.setTextAlignment(scribus.ALIGN_RIGHT, Lpic) scribus.setFont(labelFont, Lpic) scribus.setFontSize(8, Lpic) scribus.setFillColor("White", Lpic) imagecount += 1 scribus.setRedraw(1) scribus.redrawAll
 * 1) When 4 pics per page, coords are: (15, 42),(310, 187), (15, 388), (310, 533)
 * 2) When 6 pics per page: (15, 42),(310, 42), (15, 290), (310, 290),(15,533),(310,533)
 * 1) This proportion is right for photographs from my digital camera
 * 1) framecount = 0
 * 1) L is the frame at the top of each page showing the directory name
 * 1) Here is where we're loading images into the page, four at a time, then go back up for a newPage
 * 1) Lpic is the label for each picture, with position and length adjusted
 * 2) according to the text length, so if you change the font or its size,
 * 3) you may need to adjust this only approximate calculation.

else: result = scribus.messageBox ('Not Found','No Images found with\n this search selection',scribus.BUTTON_OK)

scribalbum_a4.py
This is the version that puts 8 images on A4 paper, with little extra space. Usage is as above.


 * 1) !/usr/bin/env python


 * 1) File: scribalbum_a4.py
 * 2) originally 2005.02.13  Gregory Pittman
 * 3) this version 2006.03.17 does without Tkinter
 * 4) Uses valueDialog for data entry of directory name
 * 5) and also mnemonics for image types, j=jpg, and so on.
 * 6) Also searches for uppercase equivalents.
 * 7) Makes a new document

from scribus import * import os

filetype = [] dicttype = {'j':'.jpg','p':'.png','t':'.tif','g':'.gif','P':'.pdf','J':'.jpeg'} Dicttype = {'j':'.JPG','p':'.PNG','t':'.TIF','g':'.GIF','P':'.PDF','J':'.JPEG'}

imagedir = valueDialog('Images','Enter the Image Directory') imagetype = valueDialog('Image Types','Enter the Image Types, where\n j=jpg,J=jpeg,p=png,t=tif,g=gif,P=pdf\n "jJptgP" selects all','jJptgP') for t in imagetype[0:]: filetype.append(dicttype[t]) filetype.append(Dicttype[t])

D=[] d = os.listdir(imagedir) for file in d:   for format in filetype: if file.endswith(format): D.append(file) D.sort labelFont = "DejaVu Sans" xpos = (25, 321) ypos = (42, 236, 430, 624) pwidth = 250 pheight = 187 imagecount = 0 if len(D) > 0: if newDoc(PAPER_A4, (10,10,20,20),PORTRAIT, 1, UNIT_POINTS, NOFACINGPAGES, FIRSTPAGERIGHT): while imagecount < len(D): if imagecount > 0: newPage(-1) L = createText(15, 20, 200, 20) setText("Dir: " + imagedir, L)           setTextAlignment(ALIGN_LEFT, L)            setFont(labelFont, L)            setFontSize(10, L)            for yframe in ypos: for xframe in xpos: if imagecount < len(D): f = createImage(xframe, yframe, pwidth, pheight) loadImage(imagedir + '/' + D[imagecount], f)                       setScaleImageToFrame(scaletoframe=1, proportional=1, name=f) lenfilename = len(D[imagecount]) Lpiclen = int(5.3 * lenfilename) Lpic = createText(xframe + (250 - Lpiclen), yframe + 172, Lpiclen, 15) setText(D[imagecount], Lpic) setTextAlignment(ALIGN_RIGHT, Lpic) setFont(labelFont, Lpic) setFontSize(8, Lpic) setFillColor("White", Lpic) imagecount = imagecount + 1 setRedraw(1) redrawAll
 * 1) There are 8 pictures per page; xpos and ypos are the x,y coord of the upper left corners
 * 1) This proportion is right for photographs (at least for my digital Olympus)
 * 1) L is the frame at the top of each page showing the directory name
 * 1) Here is where we're loading images into the page, eight at a time, then go back up for a newPage
 * 1) Lpic is the label for each picture, with position and length adjusted according to the text length
 * 2) so if you change in font or its size, you may need to adjust this only approximate calculation

else: result = messageBox ('Not Found','No Images found with\n this search selection',BUTTON_OK)

album_letter_2.py
This script, by Henry Hartley, is a variation on the above scribalbum_letter.py script. It supports letter size (8.5 by 11 inch) output with 4, 6, or 12 images per page. Note that the comments at the beginning of the code remain from the original script. Changes are described in the code.

To handle the creation of multiple documents with images from a collection of image directories, a modified version of the script can be found at Automatic import of images: Multiple image directories.


 * 1) !/usr/bin/env python

""" This is scribalbum_letter.py. This script will load the images from a directory, creating a new document of US Letter size.

USAGE: It is probably better not to already have any document in Scribus, since memory usage can become intense when a large number of images is used.

You are first presented with a dialog to choose either 4 or 6 images per page. Next select a directory where your images are located. Finally, select the types of image files, using the code you see in the last dialog. NOTE: If you choose PDF, only the first page will be imported, and the PDF will be rasterized.

AUTHOR: Gregory Pittman Original version: 2005.02.13, this version: 2008.07.23

LICENSE: This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

http://wiki.scribus.net/index.php/Automatic_import_of_images:_Versions_not_requiring_Tkinter

=
===========================================================

Modifications by Henry Hartley - September, 2009:


 * allow user to specify 4, 6, or 12 images per page, selected at run time
 * changed font to Garamond Regular but provide a dialog for the user to change this at run time
 * Image are arranged in one of these ways:

1 2        1  2        1  2  3    3  4        3  4        4  5  6                5  6        7  8  9                           10 11 12

been imported
 * figure out if images are landscape or portrait and adjust frame accordingly
 * center labels under images
 * offset page somewhat for 3-hole punch when printed double sided
 * replaced dir at top of all pages to a title, specified at run time
 * added page numbers (alternating corners for double sided printing)
 * the Scribus progress indicator and status line show how many files have

Note: 8.5 by 11 inch page is 612 by 792 points

If you convert all images to a size close to what is needed by this script before running it then the memory requirements are reduced. The goal is to get an image that is the same size or only slightly larger than the image frame at 300dpi. Depending upon the number of pictures per page, this will be one of the following sizes:

4 per page: 758 by 1137 pixels (182 by 273 points at 300dpi) 6 per page: 608 by 912 pixels (146 by 219 points at 300dpi) 12 per page: 421 by 633 pixels (101 by 152 points at 300dpi)

One way to do this is to create a sub-directory under your image directory called "small" and then running a perl one-liner as shown below (assuming both Perl and ImageMagick are installed, of course).

Note that the double backslash after "small" is required on MS Windows. Replace with a forward slash on Linux. The 37% used here works just about right when resizing images starting life as the 2048 by 3072 pixel images produced by my EOS D10 camera. Adjust accordingly. Fractional percentages are allowed.

perl -e "((print qq|$_\n|) && system(qq|convert -resample 300 $_ -resize 50% small\\$_|)) foreach (glob(qq|*.jpg|))"

A few minor things:

After running, I export to PDF. Scribus reports Text Overflow errors on many (or possibly all) of the text fields. These errors, it seems, may safely be ignored.

Depending on your requirements, you may want to change the Compression Quality setting in the PDF export dialog to something other than Maximum.

While this script will run on a large number of images, it slows down as it runs (on my relatively modest hardware) and you may need to break up large collections into parts.

"""

import scribus import os

filetype = [] dicttype = {'j':'.jpg','p':'.png','t':'.tif','g':'.gif','P':'.pdf'} Dicttype = {'j':'.JPG','p':'.PNG','t':'.TIF','g':'.GIF','P':'.PDF'} nrimages = '0'

while (nrimages != '4') and (nrimages != '6') and (nrimages != '12') and (nrimages != 'c'): nrimages = scribus.valueDialog('Pictures','- US Letter Paper -\n Four, six, twelve, or some "custom" number of images per page?\n\nChange to 4, 6, 12, or c as desired','4')

imagedir = scribus.fileDialog('Select Image Directory','Directories',isdir=True)

imagetype = scribus.valueDialog('Image Types','Enter the Image Types, where\n j=jpg,p=png,t=tif,g=gif,P=pdf\n "jptgP" selects all','jptgP')

gallerytitle = scribus.valueDialog('Gallery Title','Enter the title you want to appear on all pages','')

labelFont = scribus.valueDialog('Font for Text','Enter the name of the font you would like to use throughout your document','Garamond Regular')

for t in imagetype[0:]: filetype.append(dicttype[t]) filetype.append(Dicttype[t]) d = os.listdir(imagedir) D = [] for file in d:	for format in filetype: if file.endswith(format): D.append(file) D.sort


 * 1) All of these numbers can be adjusted but what is here seems to work pretty well
 * 2) If you would like to add new a new page size or layout, add a new set of values
 * 3) in this section rather than replacing an existing set.

if nrimages == '4': marginX  = 24 marginY  = 24 # Image height and width iHorW    = 273 iVerW    = 182 iVerH    = iHorW iHorH    = iVerW # Gap sizes and page offsets gapW     = 6 gapH     = 73 xOffset  = 12 yOffset  = 58 # Page title text frame titleFS  = 18 titleX   = marginX titleY   = marginY titleW   = iHorW + iHorW + gapW titleH   = titleFS * 2 # Image label text frame # Height is enough to allow a second line of text if desired. labelGap = 6 labelFS  = 12 labelH   = labelFS * 3 # Page number text frame pNumFS   = 12 pNumY    = 759 pNumXt   = 1 pNumW    = 18 pNumH    = pNumFS * 1.5 H2V = int((iHorW-iHorH)/2) V2H = int((iVerH-iVerW)/2) xPosH = [marginX, marginX + iHorW + gapW, marginX, marginX + iHorW + gapW] yPosH = [marginY + yOffset + V2H, marginY + yOffset + V2H, marginY + yOffset + iVerH + gapH + V2H, marginY + yOffset + iVerH + gapH + V2H] xPosV = [marginX + H2V, marginX + iHorW + gapW + H2V, marginX + H2V, marginX + iHorW + gapW + H2V] yPosV = [marginY + yOffset, marginY + yOffset, marginY + yOffset + iVerH + gapH, marginY + yOffset + iVerH + gapH] imgID = [0, 1, 2, 3] imgRow = 2

if nrimages == '6': marginX  = 48 marginY  = 18 # Image height and width iHorW  = 219 iVerW  = 146 iVerH = iHorW iHorH = iVerW # Gap sizes and page offsets gapW     = 30 gapH     = 18 xOffset  = 48 yOffset  = 24 # Page title text frame titleFS  = 12 titleX   = marginX titleY   = marginY titleW   = iHorW + gapW + iHorW titleH   = titleFS * 2 # Image label text frame # Height is enough to allow a second line of text if desired. labelGap = 0 labelFS  = 7 labelH   = labelFS * 3 # Page number text frame pNumFS   = 8 pNumY    = 759 pNumXt   = 1 pNumW    = 18 pNumH    = pNumFS * 1.5 H2V = int((iHorW-iHorH)/2) V2H = int((iVerH-iVerW)/2) # It's quite likely that these longs lists could be replaced by a formula. # If anyone has the time to do that, it would probably make this script easier # to maintain. xPosH = [marginX, marginX + iHorW + gapW, marginX, marginX + iHorW + gapW, marginX, marginX + iHorW + gapW] yPosH = [marginY + yOffset + V2H, marginY + yOffset + V2H, marginY + yOffset + iVerH + gapH + V2H, marginY + yOffset + iVerH + gapH + V2H, marginY + yOffset + (2 * iVerH) + (2 * gapH) + V2H, marginY + yOffset + (2 * iVerH) + (2 * gapH) + V2H] xPosV = [marginX + H2V, marginX + iHorW + gapW + H2V, marginX + H2V, marginX + iHorW + gapW + H2V, marginX + H2V, marginX + iHorW + gapW + H2V] yPosV = [marginY + yOffset, marginY + yOffset, marginY + yOffset + iVerH + gapH, marginY + yOffset + iVerH + gapH, marginY + yOffset + (2 * iVerH) + (2 * gapH), marginY + yOffset + (2 * iVerH) + (2 * gapH)] imgID = [0, 1, 2, 3, 4, 5] imgRow = 2

if nrimages == '12': marginX  = 36 marginY  = 36 # Image height and width iHorW  = 152 iVerW  = 101 iVerH = iHorW iHorH = iVerW # Gap sizes and page offsets gapW     = 24 gapH     = 21 xOffset  = 36 yOffset  = 24 # Page title text frame titleFS  = 12 titleX   = marginX titleY   = marginY titleW   = iHorW + iHorW + gapW + iHorW + gapW titleH   = titleFS * 2 # Image label text frame # Height is enough to allow a second line of text if desired. labelGap = 0 labelFS  = 7 labelH   = labelFS * 3 # Page number text frame pNumFS   = 8 pNumY    = 759 pNumXt   = 2 pNumW    = 18 pNumH    = pNumFS * 1.5 H2V = int((iHorW-iHorH)/2) V2H = int((iVerH-iVerW)/2) # It's quite likely that these longs lists could be replaced by a formula. # If anyone has the time to do that, it would probably make this script easier # to maintain. xPosH = [marginX, marginX + iHorW + gapW, marginX + (2 * iHorW) + (2 * gapW), marginX, marginX + iHorW + gapW, marginX + (2 * iHorW) + (2 * gapW), marginX, marginX + iHorW + gapW, marginX + (2 * iHorW) + (2 * gapW), marginX, marginX + iHorW + gapW, marginX + (2 * iHorW) + (2 * gapW)] yPosH = [marginY + yOffset + V2H, marginY + yOffset + V2H, marginY + yOffset + V2H, marginY + yOffset + iVerH + gapH + V2H, marginY + yOffset + iVerH + gapH + V2H, marginY + yOffset + iVerH + gapH + V2H, marginY + yOffset + (2 * iVerH) + (2 * gapH) + V2H, marginY + yOffset + (2 * iVerH) + (2 * gapH) + V2H, marginY + yOffset + (2 * iVerH) + (2 * gapH) + V2H, marginY + yOffset + (3 * iVerH) + (3 * gapH) + V2H, marginY + yOffset + (3 * iVerH) + (3 * gapH) + V2H, marginY + yOffset + (3 * iVerH) + (3 * gapH) + V2H] xPosV = [marginX + H2V, marginX + iHorW + gapW + H2V, marginX + (2 * iHorW) + (2 * gapW) + H2V, marginX + H2V, marginX + iHorW + gapW + H2V, marginX + (2 * iHorW) + (2 * gapW) + H2V, marginX + H2V, marginX + iHorW + gapW + H2V, marginX + (2 * iHorW) + (2 * gapW) + H2V, marginX + H2V, marginX + iHorW + gapW + H2V, marginX + (2 * iHorW) + (2 * gapW) + H2V] yPosV = [marginY + yOffset, marginY + yOffset, marginY + yOffset, marginY + yOffset + iVerH + gapH, marginY + yOffset + iVerH + gapH, marginY + yOffset + iVerH + gapH, marginY + yOffset + (2 * iVerH) + (2 * gapH), marginY + yOffset + (2 * iVerH) + (2 * gapH), marginY + yOffset + (2 * iVerH) + (2 * gapH), marginY + yOffset + (3 * iVerH) + (3 * gapH), marginY + yOffset + (3 * iVerH) + (3 * gapH), marginY + yOffset + (3 * iVerH) + (3 * gapH)] imgID = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] imgRow = 3


 * 1) EXTRA CATEGORY - By putting this in I have a place to put temporary numbers
 * 2) for one of a kind collections. For instance, the parameters above assume that
 * 3) images will have the 3:2 aspect ratio of 35mm film or most digital camera
 * 4) images. The numbers used here are slightly modified to work with images scanned
 * 5) from 4x5 inch negatives.

if nrimages == 'c': marginX  = 36 marginY  = 48 # Image height and width iHorW  = 125 iVerW  = 100 iVerH = iHorW iHorH = iVerW # Gap sizes and page offsets gapW     = 60 gapH     = 45 xOffset  = 39 yOffset  = 36 # Page title text frame titleFS  = 12 titleX   = marginX titleY   = marginY titleW   = iHorW + iHorW + gapW + iHorW + gapW titleH   = titleFS * 2 # Image label text frame # Height is enough to allow a second line of text if desired. labelGap = 0 labelFS  = 7 labelH   = labelFS * 3 # Page number text frame pNumFS   = 8 pNumY    = 759 pNumXt   = 2 pNumW    = 18 pNumH    = pNumFS * 1.5 H2V = int((iHorW-iHorH)/2) V2H = int((iVerH-iVerW)/2) xPosH = [marginX, marginX + iHorW + gapW, marginX + (2 * iHorW) + (2 * gapW), marginX, marginX + iHorW + gapW, marginX + (2 * iHorW) + (2 * gapW), marginX, marginX + iHorW + gapW, marginX + (2 * iHorW) + (2 * gapW), marginX, marginX + iHorW + gapW, marginX + (2 * iHorW) + (2 * gapW)] yPosH = [marginY + yOffset + V2H, marginY + yOffset + V2H, marginY + yOffset + V2H, marginY + yOffset + iVerH + gapH + V2H, marginY + yOffset + iVerH + gapH + V2H, marginY + yOffset + iVerH + gapH + V2H, marginY + yOffset + (2 * iVerH) + (2 * gapH) + V2H, marginY + yOffset + (2 * iVerH) + (2 * gapH) + V2H, marginY + yOffset + (2 * iVerH) + (2 * gapH) + V2H, marginY + yOffset + (3 * iVerH) + (3 * gapH) + V2H, marginY + yOffset + (3 * iVerH) + (3 * gapH) + V2H, marginY + yOffset + (3 * iVerH) + (3 * gapH) + V2H] xPosV = [marginX + H2V, marginX + iHorW + gapW + H2V, marginX + (2 * iHorW) + (2 * gapW) + H2V, marginX + H2V, marginX + iHorW + gapW + H2V, marginX + (2 * iHorW) + (2 * gapW) + H2V, marginX + H2V, marginX + iHorW + gapW + H2V, marginX + (2 * iHorW) + (2 * gapW) + H2V, marginX + H2V, marginX + iHorW + gapW + H2V, marginX + (2 * iHorW) + (2 * gapW) + H2V] yPosV = [marginY + yOffset, marginY + yOffset, marginY + yOffset, marginY + yOffset + iVerH + gapH, marginY + yOffset + iVerH + gapH, marginY + yOffset + iVerH + gapH, marginY + yOffset + (2 * iVerH) + (2 * gapH), marginY + yOffset + (2 * iVerH) + (2 * gapH), marginY + yOffset + (2 * iVerH) + (2 * gapH), marginY + yOffset + (3 * iVerH) + (3 * gapH), marginY + yOffset + (3 * iVerH) + (3 * gapH), marginY + yOffset + (3 * iVerH) + (3 * gapH)] imgID = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] imgRow = 3

imageCount = 0 pageNumber = 1 scribus.progressTotal(len(D)) if len(D) > 0: if scribus.newDoc(scribus.PAPER_LETTER, (marginX, marginX, marginY, marginY),scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.NOFACINGPAGES, scribus.FIRSTPAGERIGHT): while imageCount < len(D): if imageCount > 0: scribus.newPage(-1) # Here is where we're loading images into the page, four, six, or twelve at a time, then go back up for a newPage if pageNumber % 2 == 0: pOffset = 0 pNumX = xPosH[0] else: pOffset = xOffset pNumX = xPosH[pNumXt] + iHorW + pOffset - pNumW

# L is the frame at the top of each page showing the gallery title (read in above) L = scribus.createText(titleX + pOffset, titleY, titleW, titleH) scribus.setText(gallerytitle, L)			scribus.setTextAlignment(scribus.ALIGN_CENTERED, L)			scribus.setFont(labelFont, L)			scribus.setFontSize(titleFS, L)			for i in imgID: if imageCount < len(D):

scribus.statusMessage("Placing image " + D[imageCount] + " in document (" + `imageCount` + " of " + `len(D)` + ")") scribus.progressSet(imageCount)

# Create a temporary image object. Size and location are irrelivant tempImage = scribus.createImage(10, 10, 10, 10)

# Populate that object with your image scribus.loadImage(imagedir + '/' + D[imageCount], tempImage)

# Scale the image but NOT proportionally scribus.setScaleImageToFrame(scaletoframe=1, proportional=0, name=tempImage)

# Use getImageScale to get the relative scaling in the x and y directions imgx,imgy = scribus.getImageScale(tempImage)

# If imgx < imgy, you have an horizontal image, otherwise, # a vertical (or square) image. if imgx < imgy: x = xPosH[i] + pOffset y = yPosH[i] pWidth = iHorW pHeight = iHorH else: x = xPosV[i] + pOffset y = yPosV[i] pWidth = iVerW pHeight = iVerH

# Can't have these cluttering up the page scribus.deleteObject(tempImage) # Now we create the REAL image object placed appropriately f = scribus.createImage(x, y, pWidth, pHeight) # and load the image scribus.loadImage(imagedir + '/' + D[imageCount], f)					# this time when we scale the image, we do it proportionally scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=f) # Lpic is the label for each picture, the position is the same for all #	image orientations and the labels are centered under the pictures. # Create the text frame. Lpic = scribus.createText(xPosH[i] + pOffset, yPosV[i] + iVerH + labelGap, iHorW, labelH) # populate with the file name scribus.setText(D[imageCount], Lpic) # and format as desired scribus.setTextAlignment(scribus.ALIGN_CENTERED, Lpic) scribus.setFont(labelFont, Lpic) scribus.setFontSize(labelFS, Lpic) # increment the image count imageCount += 1 # Now the page number # Create a text frame pNum = scribus.createText(pNumX, pNumY, pNumW, pNumH) # Put the page number in it and format scribus.setText(`pageNumber`, pNum) if imageCount < len(D): scribus.setTextAlignment(scribus.ALIGN_RIGHT, pNum) else: scribus.setTextAlignment(scribus.ALIGN_LEFT, pNum) scribus.setFont(labelFont, pNum) scribus.setFontSize(pNumFS, pNum) # Finally, we increment the page number pageNumber += 1 scribus.setRedraw(1) scribus.redrawAll

else: result = scribus.messageBox ('Not Found','No Images found with\n this search selection',scribus.BUTTON_OK)

scribus.setRedraw(1) scribus.redrawAll

scribus.statusMessage("") scribus.progressReset