https://wiki.scribus.net/wiki/api.php?action=feedcontributions&user=Hhartley&feedformat=atomScribus Wiki - User contributions [en]2024-03-28T15:25:28ZUser contributionsMediaWiki 1.39.1https://wiki.scribus.net/wiki/index.php?title=Automatic_import_of_images:_Multiple_image_directories&diff=26126Automatic import of images: Multiple image directories2011-06-28T16:47:30Z<p>Hhartley: Script now supports image titles from accompanying text file</p>
<hr />
<div>As an amateur photographer, I take a lot of pictures and in general I post them to a web site with one or more galleries being generated most days. For general purposes, that's enough. Occasionally, however, I've found it useful to have a printed version of my images, to be used more as like the contact sheet of old than as publication quality images. I'd like these documents to have small versions of all the images in each gallery, labeled with the file name and an option title that identified the subject of the photograph. Since the display of images on the web site is driven by text files with file names, titles, and descriptions, I it made sense to reuse that text file for labeling the pictures on the contact sheets.<br />
<br />
Starting with the script found on the page [[Automatic import of images: Versions not requiring Tkinter#album_letter_2.py]], I have created a new script that will take a collection of image directories and create 12-images-per-page documents from each of them in turn, save the documents and generate PDF files from each.<br />
<br />
The initial input and output directories are specified in the code and will need to be changed based on your own configuration. They are defined on lines 27 and 31. The file that I use to list the images is index.txt but this file name may also be changed on line 42. Finally, the font to use is set on line 45. While there are many other settings that may be adjusted, the script should work well enough with just those four items set. Note that the script will not create the output directory so you'll need to make sure it exists before you start.<br />
<br />
The basic idea here is to go through the source directory and gather all the sub-directory names. Then, go through each of those sub-directories, open the index.txt file, and generate a document with the images listed there, 12 per page. The document places the sub-directory name at the top of each page, arranges the images in four rows of three images with the file names centered under each. Page numbers are added. Since I print these documents double sided, the page numbers move from side to side and the entire page contents are shifted a little to the right (odd numbered pages) or the left (even numbered pages). Each gallery gets its own file.<br />
<br />
Once generated, an SLA file is saved in the outputDirectory specified on line 31. Then, a PDF is generated with all pages and saved to the same location. Both files are named the same as the image sub-directory but with .sla and .pdf extensions respectively. <br />
<br />
'''CAUTION''': if you have directories with too many or very large image files, this can take a long while to run. Documents for directories with a couple dozen images of the appropriate size are created, saved, and exported to PDF in a matter of seconds. Documents for directories with images much larger than necessary or with more than a couple hundred images can take many minutes to be created. Since the images are printed at just over 1.4 by 2.1 inches, even at 300 dpi they will only need to be 420 by 633 pixels and you can probably get away with less. I would be cautious running this script on directories with lots of images or those copied directly from your digital camera. I've successfully produced documents with 640 images this way but it took a good while.<br />
<br />
For publication to my web site I use a script that creates thumbnail, small, and large versions of each photo. Since the small size images are 467 by 700 pixels, I use those when generating contact sheets with this script. That works quite well and I've created documents with 1,500 images without any problem. Note that images are the same size whether they are vertical or horizontal. Even with this precaution, when I run this on a large number of directories, I often, eventually, get a Scribus crash with the message: <br />
<br />
:Scribus crashes due to the following exception : EXCEPTION_ACCESS_VIOLATION<br />
<br />
I just close Scribus, move the image directories that have already been processed and start again. If anyone knows what's causing that and can fix it, that would be wonderful.<br />
<br />
Considerable credit and thanks to Gregory Pittman, who wrote the original script on which this is based.<br />
<br />
<pre><nowiki><br />
#!/usr/bin/env python<br />
<br />
"""<br />
This is contact-sheet.py. This script will load the images from any number<br />
of directories, creating a new document of US Letter size from each directory.<br />
<br />
AUTHOR: Henry Hartley<br />
DATE: December 2, 2010 (original version)<br />
MODIFICATIONS:<br />
June 28, 2011 - Added support for reading file information from index.txt<br />
<br />
LICENSE: This program is free software; you can redistribute it and/or modify <br />
it under the terms of the GNU General Public License as published by the Free <br />
Software Foundation; either version 2 of the License, or (at your option) any <br />
later version.<br />
<br />
http://wiki.scribus.net/index.php/Automatic_import_of_images:_Multiple_image_directories<br />
<br />
<br />
<br />
You will probably need to edit the following:<br />
<br />
"""<br />
# The directory that contains images or subdirectories with images.<br />
# All subdirectories under this location will be used to create <br />
# separate output files<br />
sourceDirectory = "C:/temp/photo/"<br />
<br />
# The directory, which should already exist, where you want your output files <br />
# to be written<br />
outputDirectory = "C:/temp/photo/"<br />
<br />
# The name of a file that contains one line per image. Each line should consist of <br />
# a tab delimited string with the following file information: <br />
# <br />
# 0 - count -- Actually, anything can be here except a blank space or a hash<br />
# mark (#), which will cause the line to be ignored.<br />
# 1 - file name -- The name of the file without the .jpg extension<br />
# 2 - image title -- The title to use in labeling the file (optional)<br />
# 3 - description -- A longer description (optional) (currently not used)<br />
# <br />
sourceFileList = 'index.txt'<br />
<br />
# The font to use for documents<br />
labelFont = 'Garamond Regular'<br />
<br />
<br />
####################################################################################<br />
## While you might want to edit setting below here, you <br />
## shouldn't need to in order to run the script<br />
####################################################################################<br />
<br />
import scribus<br />
import os<br />
<br />
# All of these numbers can be adjusted but what is here seems to work pretty well<br />
<br />
firstPageNumber = '1'<br />
<br />
marginX = 36<br />
marginY = 36<br />
<br />
# Image height and width<br />
iHorW = 152<br />
iVerW = 101<br />
iVerH = iHorW<br />
iHorH = iVerW<br />
<br />
# Gap sizes and page offsets<br />
gapW = 24<br />
gapH = 21<br />
xOffset = 36<br />
yOffset = 24<br />
<br />
# Page title text frame<br />
titleFS = 12<br />
titleX = marginX<br />
titleY = marginY<br />
titleW = iHorW + iHorW + gapW + iHorW + gapW<br />
titleH = titleFS * 2<br />
<br />
# Image label text frame<br />
# Height is enough to allow a second line of text if desired.<br />
labelGap = 0<br />
labelFS = 6<br />
labelH = labelFS * 4<br />
<br />
# Page number text frame<br />
pNumFS = 8<br />
pNumY = 759<br />
pNumXt = 2<br />
pNumW = 18<br />
pNumH = pNumFS * 1.5<br />
<br />
H2V = int((iHorW-iHorH)/2)<br />
V2H = int((iVerH-iVerW)/2)<br />
<br />
# It's quite likely that these longs lists could be replaced by a formula.<br />
# If anyone has the time to do that, it would probably make this script easier<br />
# to maintain. Still, this works.<br />
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)]<br />
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]<br />
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]<br />
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)]<br />
imgID = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]<br />
imgRow = 3<br />
imagedir = ""<br />
<br />
dirCount = 0<br />
dir = os.listdir(sourceDirectory)<br />
DIR = []<br />
for file in dir:<br />
#result = scribus.messageBox("Directory", "File: "+file)<br />
if os.path.isdir(sourceDirectory+file):<br />
DIR.append(file)<br />
dirCount += 1<br />
DIR.sort()<br />
<br />
#result = scribus.messageBox("Directory Count", "There were "+str(dirCount)+" directories added to the array")<br />
<br />
for imagedir in DIR:<br />
<br />
# Open the index.txt file<br />
f = open(sourceDirectory+imagedir+'/'+sourceFileList, 'r')<br />
D = []<br />
D = f.readlines()<br />
<br />
gallerytitle = imagedir<br />
<br />
imageCount = 0<br />
pageNumber = 1<br />
scribus.progressTotal(len(D))<br />
if len(D) > 0:<br />
if scribus.newDoc(scribus.PAPER_LETTER, (marginX, marginX, marginY, marginY),scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.NOFACINGPAGES, scribus.FIRSTPAGERIGHT):<br />
while imageCount < len(D):<br />
if imageCount > 0:<br />
scribus.newPage(-1)<br />
<br />
# Here is where we're loading images into the page, four, six, or twelve at a time, then go back up for a newPage<br />
if pageNumber % 2 == 0:<br />
pOffset = 0<br />
pNumX = xPosH[0]<br />
else:<br />
pOffset = xOffset<br />
pNumX = xPosH[pNumXt] + iHorW + pOffset - pNumW<br />
<br />
# L is the frame at the top of each page showing the gallery title (read in above)<br />
L = scribus.createText(titleX + pOffset, titleY, titleW, titleH)<br />
scribus.setText(gallerytitle, L)<br />
scribus.setTextAlignment(scribus.ALIGN_CENTERED, L)<br />
scribus.setFont(labelFont, L)<br />
scribus.setFontSize(titleFS, L)<br />
<br />
for i in imgID:<br />
if imageCount < len(D):<br />
<br />
if not D[imageCount].startswith("#") and not D[imageCount].startswith(" "):<br />
Img = []<br />
Img = D[imageCount].split("\t")<br />
<br />
scribus.statusMessage("Placing image " + Img[1] + " in document (" + `imageCount` + " of " + `len(D)` + ")")<br />
scribus.progressSet(imageCount)<br />
<br />
# Create a temporary image object. Size and location are irrelivant<br />
tempImage = scribus.createImage(10, 10, 10, 10)<br />
<br />
# Populate that object with your image<br />
scribus.loadImage(sourceDirectory+imagedir + '/' + Img[1]+'.jpg', tempImage)<br />
<br />
# Scale the image but NOT proportionally<br />
scribus.setScaleImageToFrame(scaletoframe=1, proportional=0, name=tempImage)<br />
<br />
# Use getImageScale to get the relative scaling in the x and y directions<br />
imgx,imgy = scribus.getImageScale(tempImage)<br />
<br />
# If imgx < imgy, you have an horizontal image, otherwise, <br />
# a vertical (or square) image. <br />
if imgx < imgy:<br />
x = xPosH[i] + pOffset<br />
y = yPosH[i]<br />
pWidth = iHorW<br />
pHeight = iHorH<br />
else:<br />
x = xPosV[i] + pOffset<br />
y = yPosV[i]<br />
pWidth = iVerW<br />
pHeight = iVerH<br />
<br />
# Can't have these cluttering up the page<br />
scribus.deleteObject(tempImage)<br />
<br />
# Now we create the REAL image object placed appropriately<br />
f = scribus.createImage(x, y, pWidth, pHeight)<br />
<br />
# and load the image<br />
scribus.loadImage(sourceDirectory+imagedir + '/' + Img[1]+'.jpg', f)<br />
<br />
# this time when we scale the image, we do it proportionally<br />
scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=f)<br />
<br />
# Lpic is the label for each picture, the position is the same for all <br />
# image orientations and the labels are centered under the pictures.<br />
<br />
# Create a text frame for the picture caption<br />
Lpic = scribus.createText(xPosH[i] + pOffset - int(gapW/2)-1, yPosV[i] + iVerH + labelGap, iHorW + gapW-2, labelH)<br />
<br />
# populate with the file name and title (Img[2])<br />
if len(Img[2]) > 0:<br />
scribus.setText('File: '+Img[1]+', '+Img[2], Lpic)<br />
else:<br />
scribus.setText('File: '+Img[1], Lpic)<br />
<br />
# and format as desired<br />
scribus.setTextAlignment(scribus.ALIGN_CENTERED, Lpic)<br />
scribus.setFont(labelFont, Lpic)<br />
scribus.setFontSize(labelFS, Lpic)<br />
scribus.setLineSpacing(labelFS, Lpic)<br />
#scribus.setFillColor("White", Lpic)<br />
<br />
# End of If/Then -- startswith()<br />
<br />
# increment the image count<br />
imageCount += 1<br />
<br />
# Now the page number<br />
<br />
# Create a text frame<br />
pNum = scribus.createText(pNumX, pNumY, pNumW, pNumH)<br />
<br />
# Put the page number in it and format<br />
pageNumberPrint = pageNumber + (int(firstPageNumber)-1)<br />
scribus.setText(`pageNumberPrint`, pNum)<br />
if imageCount < len(D):<br />
scribus.setTextAlignment(scribus.ALIGN_RIGHT, pNum)<br />
else:<br />
scribus.setTextAlignment(scribus.ALIGN_LEFT, pNum)<br />
scribus.setFont(labelFont, pNum)<br />
scribus.setFontSize(pNumFS, pNum)<br />
#scribus.setFillColor("White", pNum)<br />
<br />
# Finally, we increment the page number<br />
pageNumber += 1<br />
scribus.setRedraw(1)<br />
scribus.redrawAll()<br />
<br />
else:<br />
result = scribus.messageBox ('Not Found','No Images found with\n this search selection',scribus.BUTTON_OK)<br />
<br />
scribus.setRedraw(1)<br />
scribus.redrawAll()<br />
<br />
scribus.statusMessage("Saving File as "+outputDirectory+imagedir+".sla")<br />
#result = scribus.messageBox("Save", "Saving SLA File as: "+outputDirectory+imagedir+".sla")<br />
scribus.saveDocAs(outputDirectory+imagedir+".sla")<br />
<br />
scribus.statusMessage("Saving PDF File as "+outputDirectory+imagedir+".pdf")<br />
pdfExport = scribus.PDFfile()<br />
pdfExport.info = outputDirectory+imagedir+".pdf"<br />
pNum = 1<br />
PDFPages = []<br />
while pNum < pageNumber:<br />
PDFPages.append(pNum)<br />
pNum += 1<br />
pdfExport.pages = PDFPages<br />
pdfExport.file = outputDirectory+imagedir+".pdf"<br />
pdfExport.save()<br />
<br />
scribus.closeDoc()<br />
<br />
scribus.statusMessage("")<br />
scribus.progressReset()<br />
<br />
<br />
</nowiki></pre></div>Hhartleyhttps://wiki.scribus.net/wiki/index.php?title=Automatic_import_of_images:_Multiple_image_directories&diff=23022Automatic import of images: Multiple image directories2010-12-02T21:13:40Z<p>Hhartley: Add crash notice info</p>
<hr />
<div>Starting with the script found on the page [[Automatic import of images: Versions not requiring Tkinter#album_letter_2.py]], I have created a new script that will take a collection of image directories and create 12-images-per-page documents from each of them in turn, save the documents and generate PDF files from each.<br />
<br />
The initial input and output directories are specified in the code and will need to be changed based on your own configuration. They are defined on lines 21 and 22. There are many other settings that may be adjusted but this should work well enough as a starting point. Note that the script will not create the output directory so you'll need to make sure it exists before you start.<br />
<br />
The basic idea here is to go through the source directory and gather all the sub-directory names. Then, go through each of those sub-directories and generate a document with the images found there, 12 per page. The document places the sub-directory name at the top of each page, arranges the images in four rows of three images with the file names centered under each. Page numbers are added. Since I print these documents double sided, the page numbers move from side to side and the entire page contents are shifted a little to the right (odd numbered pages) or the left (even numbered pages). Each gallery gets its own file.<br />
<br />
Once generated, an SLA file is saved in the outputDirectory specified on line 22. Then, a PDF is generated with all pages and saved to the same location. Both files are named the same as the image sub-directory but with .sla and .pdf extensions respectively. <br />
<br />
Caution: if you have directories with too many or very large image files, this can take a long while to run. Documents for directories with a dozen or two images of the appropriate size are created, saved, and exported to PDF in a matter of seconds. Documents for directories with images much larger than necessary or with more than a couple hundred images can take many minutes to be created. Since the images are printed at just over 1.4 by 2.1 inches, even at 300 dpi they will only need to be 420 by 633 pixels and you can probably get away with less. I would be cautious running this script on directories with lots of images or those copied directly from your digital camera. I've successfully produced documents with 640 images this way but it took a good while.<br />
<br />
When I run this on a large number of directories, I often, eventually, get a Scribus Crash with the message: Scribus crashes due to the following exception : EXCEPTION_ACCESS_VIOLATION. I just close Scribus, move the image directories that have already been processed and start again. If anyone knows what's causing that and can fix it, that would be wonderful.<br />
<br />
Considerable credit and thanks to Gregory Pittman, who wrote the original script on which this is based.<br />
<br />
<pre><nowiki><br />
#!/usr/bin/env python<br />
<br />
"""<br />
This is contact-sheet.py. This script will load the images from any number<br />
of directories, creating a new document of US Letter size from each directory.<br />
<br />
AUTHOR: Henry Hartley, December 2, 2010, with thanks to Gregory Pittman<br />
<br />
LICENSE: This program is free software; you can redistribute it and/or modify <br />
it under the terms of the GNU General Public License as published by the Free <br />
Software Foundation; either version 2 of the License, or (at your option) any <br />
later version.<br />
<br />
http://wiki.scribus.net/index.php/Automatic_import_of_images:_Multiple_image_directories<br />
<br />
"""<br />
<br />
import scribus<br />
import os<br />
<br />
sourceDirectory = "C:/temp/photographs/images/"<br />
outputDirectory = "C:/temp/photographs/contact_sheets/"<br />
<br />
filetype = []<br />
dicttype = {'j':'.jpg','p':'.png','t':'.tif','g':'.gif','P':'.pdf'}<br />
Dicttype = {'j':'.JPG','p':'.PNG','t':'.TIF','g':'.GIF','P':'.PDF'}<br />
<br />
firstPageNumber = '1'<br />
imagetype = 'jptgP'<br />
labelFont = 'Garamond Regular'<br />
<br />
for t in imagetype[0:]:<br />
filetype.append(dicttype[t])<br />
filetype.append(Dicttype[t])<br />
<br />
# All of these numbers can be adjusted but what is here seems to work pretty well<br />
<br />
marginX = 36<br />
marginY = 36<br />
<br />
# Image height and width<br />
iHorW = 152<br />
iVerW = 101<br />
iVerH = iHorW<br />
iHorH = iVerW<br />
<br />
# Gap sizes and page offsets<br />
gapW = 24<br />
gapH = 21<br />
xOffset = 36<br />
yOffset = 24<br />
<br />
# Page title text frame<br />
titleFS = 12<br />
titleX = marginX<br />
titleY = marginY<br />
titleW = iHorW + iHorW + gapW + iHorW + gapW<br />
titleH = titleFS * 2<br />
<br />
# Image label text frame<br />
# Height is enough to allow a second line of text if desired.<br />
labelGap = 0<br />
labelFS = 7<br />
labelH = labelFS * 3<br />
<br />
# Page number text frame<br />
pNumFS = 8<br />
pNumY = 759<br />
pNumXt = 2<br />
pNumW = 18<br />
pNumH = pNumFS * 1.5<br />
<br />
H2V = int((iHorW-iHorH)/2)<br />
V2H = int((iVerH-iVerW)/2)<br />
<br />
# It's quite likely that these longs lists could be replaced by a formula.<br />
# If anyone has the time to do that, it would probably make this script easier<br />
# to maintain.<br />
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)]<br />
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]<br />
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]<br />
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)]<br />
imgID = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]<br />
imgRow = 3<br />
imagedir = ""<br />
<br />
dirCount = 0<br />
dir = os.listdir(sourceDirectory)<br />
DIR = []<br />
for file in dir:<br />
#result = scribus.messageBox("Directory", "File: "+file)<br />
if os.path.isdir(sourceDirectory+file):<br />
DIR.append(file)<br />
dirCount += 1<br />
DIR.sort()<br />
<br />
#result = scribus.messageBox("Directory Count", "There were "+str(dirCount)+" directories added to the array")<br />
<br />
for imagedir in DIR:<br />
#result = scribus.messageBox("Directory", "The directory about to be processed is: "+imagedir)<br />
d = os.listdir(sourceDirectory+imagedir)<br />
D = []<br />
for file in d:<br />
for format in filetype:<br />
if file.endswith(format):<br />
D.append(file)<br />
D.sort()<br />
<br />
gallerytitle = imagedir<br />
<br />
imageCount = 0<br />
pageNumber = 1<br />
scribus.progressTotal(len(D))<br />
if len(D) > 0:<br />
if scribus.newDoc(scribus.PAPER_LETTER, (marginX, marginX, marginY, marginY),scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.NOFACINGPAGES, scribus.FIRSTPAGERIGHT):<br />
while imageCount < len(D):<br />
if imageCount > 0:<br />
scribus.newPage(-1)<br />
<br />
# Here is where we're loading images into the page, four, six, or twelve at a time, then go back up for a newPage<br />
if pageNumber % 2 == 0:<br />
pOffset = 0<br />
pNumX = xPosH[0]<br />
else:<br />
pOffset = xOffset<br />
pNumX = xPosH[pNumXt] + iHorW + pOffset - pNumW<br />
<br />
# L is the frame at the top of each page showing the gallery title (read in above)<br />
L = scribus.createText(titleX + pOffset, titleY, titleW, titleH)<br />
scribus.setText(gallerytitle, L)<br />
scribus.setTextAlignment(scribus.ALIGN_CENTERED, L)<br />
scribus.setFont(labelFont, L)<br />
scribus.setFontSize(titleFS, L)<br />
<br />
for i in imgID:<br />
if imageCount < len(D):<br />
<br />
scribus.statusMessage("Placing image " + D[imageCount] + " in document (" + `imageCount` + " of " + `len(D)` + ")")<br />
scribus.progressSet(imageCount)<br />
<br />
# Create a temporary image object. Size and location are irrelivant<br />
tempImage = scribus.createImage(10, 10, 10, 10)<br />
<br />
# Populate that object with your image<br />
scribus.loadImage(sourceDirectory+imagedir + '/' + D[imageCount], tempImage)<br />
<br />
# Scale the image but NOT proportionally<br />
scribus.setScaleImageToFrame(scaletoframe=1, proportional=0, name=tempImage)<br />
<br />
# Use getImageScale to get the relative scaling in the x and y directions<br />
imgx,imgy = scribus.getImageScale(tempImage)<br />
<br />
# If imgx < imgy, you have an horizontal image, otherwise, <br />
# a vertical (or square) image. <br />
if imgx < imgy:<br />
x = xPosH[i] + pOffset<br />
y = yPosH[i]<br />
pWidth = iHorW<br />
pHeight = iHorH<br />
else:<br />
x = xPosV[i] + pOffset<br />
y = yPosV[i]<br />
pWidth = iVerW<br />
pHeight = iVerH<br />
<br />
# Can't have these cluttering up the page<br />
scribus.deleteObject(tempImage)<br />
<br />
# Now we create the REAL image object placed appropriately<br />
f = scribus.createImage(x, y, pWidth, pHeight)<br />
<br />
# and load the image<br />
scribus.loadImage(sourceDirectory+imagedir + '/' + D[imageCount], f)<br />
<br />
# this time when we scale the image, we do it proportionally<br />
scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=f)<br />
<br />
# Lpic is the label for each picture, the position is the same for all <br />
# image orientations and the labels are centered under the pictures.<br />
<br />
# Create the text frame.<br />
Lpic = scribus.createText(xPosH[i] + pOffset, yPosV[i] + iVerH + labelGap, iHorW, labelH)<br />
<br />
# populate with the file name<br />
scribus.setText(D[imageCount], Lpic)<br />
<br />
# and format as desired<br />
scribus.setTextAlignment(scribus.ALIGN_CENTERED, Lpic)<br />
scribus.setFont(labelFont, Lpic)<br />
scribus.setFontSize(labelFS, Lpic)<br />
#scribus.setFillColor("White", Lpic)<br />
<br />
# increment the image count<br />
imageCount += 1<br />
<br />
# Now the page number<br />
<br />
# Create a text frame<br />
pNum = scribus.createText(pNumX, pNumY, pNumW, pNumH)<br />
<br />
# Put the page number in it and format<br />
pageNumberPrint = pageNumber + (int(firstPageNumber)-1)<br />
scribus.setText(`pageNumberPrint`, pNum)<br />
if imageCount < len(D):<br />
scribus.setTextAlignment(scribus.ALIGN_RIGHT, pNum)<br />
else:<br />
scribus.setTextAlignment(scribus.ALIGN_LEFT, pNum)<br />
scribus.setFont(labelFont, pNum)<br />
scribus.setFontSize(pNumFS, pNum)<br />
#scribus.setFillColor("White", pNum)<br />
<br />
# Finally, we increment the page number<br />
pageNumber += 1<br />
scribus.setRedraw(1)<br />
scribus.redrawAll()<br />
<br />
else:<br />
result = scribus.messageBox ('Not Found','No Images found with\n this search selection',scribus.BUTTON_OK)<br />
<br />
scribus.setRedraw(1)<br />
scribus.redrawAll()<br />
<br />
scribus.statusMessage("Saving File as "+outputDirectory+imagedir)<br />
#result = scribus.messageBox("Save", "Saving SLA File as: "+outputDirectory+imagedir+".sla")<br />
scribus.saveDocAs(outputDirectory+imagedir+".sla")<br />
<br />
scribus.statusMessage("Saving PDF File as "+outputDirectory+imagedir)<br />
pdfExport = scribus.PDFfile()<br />
pdfExport.info = outputDirectory+imagedir+".pdf"<br />
pNum = 1<br />
PDFPages = []<br />
while pNum < pageNumber:<br />
PDFPages.append(pNum)<br />
pNum += 1<br />
pdfExport.pages = PDFPages<br />
pdfExport.file = outputDirectory+imagedir+".pdf"<br />
pdfExport.save()<br />
<br />
scribus.closeDoc()<br />
<br />
scribus.statusMessage("")<br />
scribus.progressReset()<br />
<br />
</nowiki></pre></div>Hhartleyhttps://wiki.scribus.net/wiki/index.php?title=Automatic_import_of_images:_Multiple_image_directories&diff=23021Automatic import of images: Multiple image directories2010-12-02T18:35:37Z<p>Hhartley: </p>
<hr />
<div>Starting with the script found on the page [[Automatic import of images: Versions not requiring Tkinter#album_letter_2.py]], I have created a new script that will take a collection of image directories and create 12-images-per-page documents from each of them in turn, save the documents and generate PDF files from each.<br />
<br />
The initial input and output directories are specified in the code and will need to be changed based on your own configuration. They are defined on lines 21 and 22. There are many other settings that may be adjusted but this should work well enough as a starting point. Note that the script will not create the output directory so you'll need to make sure it exists before you start.<br />
<br />
The basic idea here is to go through the source directory and gather all the sub-directory names. Then, go through each of those sub-directories and generate a document with the images found there, 12 per page. The document places the sub-directory name at the top of each page, arranges the images in four rows of three images with the file names centered under each. Page numbers are added. Since I print these documents double sided, the page numbers move from side to side and the entire page contents are shifted a little to the right (odd numbered pages) or the left (even numbered pages). Each gallery gets its own file.<br />
<br />
Once generated, an SLA file is saved in the outputDirectory specified on line 22. Then, a PDF is generated with all pages and saved to the same location. Both files are named the same as the image sub-directory but with .sla and .pdf extensions respectively. <br />
<br />
Caution: if you have directories with too many or very large image files, this can take a long while to run. Documents for directories with a dozen or two images of the appropriate size are created, saved, and exported to PDF in a matter of seconds. Documents for directories with images much larger than necessary or with more than a couple hundred images can take many minutes to be created. Since the images are printed at just over 1.4 by 2.1 inches, even at 300 dpi they will only need to be 420 by 633 pixels and you can probably get away with less. I would be cautious running this script on directories with lots of images or those copied directly from your digital camera.<br />
<br />
Considerable credit and thanks to Gregory Pittman, who wrote the original script on which this is based.<br />
<br />
<pre><nowiki><br />
#!/usr/bin/env python<br />
<br />
"""<br />
This is contact-sheet.py. This script will load the images from any number<br />
of directories, creating a new document of US Letter size from each directory.<br />
<br />
AUTHOR: Henry Hartley, December 2, 2010, with thanks to Gregory Pittman<br />
<br />
LICENSE: This program is free software; you can redistribute it and/or modify <br />
it under the terms of the GNU General Public License as published by the Free <br />
Software Foundation; either version 2 of the License, or (at your option) any <br />
later version.<br />
<br />
http://wiki.scribus.net/index.php/Automatic_import_of_images:_Multiple_image_directories<br />
<br />
"""<br />
<br />
import scribus<br />
import os<br />
<br />
sourceDirectory = "C:/temp/photographs/images/"<br />
outputDirectory = "C:/temp/photographs/contact_sheets/"<br />
<br />
filetype = []<br />
dicttype = {'j':'.jpg','p':'.png','t':'.tif','g':'.gif','P':'.pdf'}<br />
Dicttype = {'j':'.JPG','p':'.PNG','t':'.TIF','g':'.GIF','P':'.PDF'}<br />
<br />
firstPageNumber = '1'<br />
imagetype = 'jptgP'<br />
labelFont = 'Garamond Regular'<br />
<br />
for t in imagetype[0:]:<br />
filetype.append(dicttype[t])<br />
filetype.append(Dicttype[t])<br />
<br />
# All of these numbers can be adjusted but what is here seems to work pretty well<br />
<br />
marginX = 36<br />
marginY = 36<br />
<br />
# Image height and width<br />
iHorW = 152<br />
iVerW = 101<br />
iVerH = iHorW<br />
iHorH = iVerW<br />
<br />
# Gap sizes and page offsets<br />
gapW = 24<br />
gapH = 21<br />
xOffset = 36<br />
yOffset = 24<br />
<br />
# Page title text frame<br />
titleFS = 12<br />
titleX = marginX<br />
titleY = marginY<br />
titleW = iHorW + iHorW + gapW + iHorW + gapW<br />
titleH = titleFS * 2<br />
<br />
# Image label text frame<br />
# Height is enough to allow a second line of text if desired.<br />
labelGap = 0<br />
labelFS = 7<br />
labelH = labelFS * 3<br />
<br />
# Page number text frame<br />
pNumFS = 8<br />
pNumY = 759<br />
pNumXt = 2<br />
pNumW = 18<br />
pNumH = pNumFS * 1.5<br />
<br />
H2V = int((iHorW-iHorH)/2)<br />
V2H = int((iVerH-iVerW)/2)<br />
<br />
# It's quite likely that these longs lists could be replaced by a formula.<br />
# If anyone has the time to do that, it would probably make this script easier<br />
# to maintain.<br />
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)]<br />
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]<br />
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]<br />
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)]<br />
imgID = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]<br />
imgRow = 3<br />
imagedir = ""<br />
<br />
dirCount = 0<br />
dir = os.listdir(sourceDirectory)<br />
DIR = []<br />
for file in dir:<br />
#result = scribus.messageBox("Directory", "File: "+file)<br />
if os.path.isdir(sourceDirectory+file):<br />
DIR.append(file)<br />
dirCount += 1<br />
DIR.sort()<br />
<br />
#result = scribus.messageBox("Directory Count", "There were "+str(dirCount)+" directories added to the array")<br />
<br />
for imagedir in DIR:<br />
#result = scribus.messageBox("Directory", "The directory about to be processed is: "+imagedir)<br />
d = os.listdir(sourceDirectory+imagedir)<br />
D = []<br />
for file in d:<br />
for format in filetype:<br />
if file.endswith(format):<br />
D.append(file)<br />
D.sort()<br />
<br />
gallerytitle = imagedir<br />
<br />
imageCount = 0<br />
pageNumber = 1<br />
scribus.progressTotal(len(D))<br />
if len(D) > 0:<br />
if scribus.newDoc(scribus.PAPER_LETTER, (marginX, marginX, marginY, marginY),scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.NOFACINGPAGES, scribus.FIRSTPAGERIGHT):<br />
while imageCount < len(D):<br />
if imageCount > 0:<br />
scribus.newPage(-1)<br />
<br />
# Here is where we're loading images into the page, four, six, or twelve at a time, then go back up for a newPage<br />
if pageNumber % 2 == 0:<br />
pOffset = 0<br />
pNumX = xPosH[0]<br />
else:<br />
pOffset = xOffset<br />
pNumX = xPosH[pNumXt] + iHorW + pOffset - pNumW<br />
<br />
# L is the frame at the top of each page showing the gallery title (read in above)<br />
L = scribus.createText(titleX + pOffset, titleY, titleW, titleH)<br />
scribus.setText(gallerytitle, L)<br />
scribus.setTextAlignment(scribus.ALIGN_CENTERED, L)<br />
scribus.setFont(labelFont, L)<br />
scribus.setFontSize(titleFS, L)<br />
<br />
for i in imgID:<br />
if imageCount < len(D):<br />
<br />
scribus.statusMessage("Placing image " + D[imageCount] + " in document (" + `imageCount` + " of " + `len(D)` + ")")<br />
scribus.progressSet(imageCount)<br />
<br />
# Create a temporary image object. Size and location are irrelivant<br />
tempImage = scribus.createImage(10, 10, 10, 10)<br />
<br />
# Populate that object with your image<br />
scribus.loadImage(sourceDirectory+imagedir + '/' + D[imageCount], tempImage)<br />
<br />
# Scale the image but NOT proportionally<br />
scribus.setScaleImageToFrame(scaletoframe=1, proportional=0, name=tempImage)<br />
<br />
# Use getImageScale to get the relative scaling in the x and y directions<br />
imgx,imgy = scribus.getImageScale(tempImage)<br />
<br />
# If imgx < imgy, you have an horizontal image, otherwise, <br />
# a vertical (or square) image. <br />
if imgx < imgy:<br />
x = xPosH[i] + pOffset<br />
y = yPosH[i]<br />
pWidth = iHorW<br />
pHeight = iHorH<br />
else:<br />
x = xPosV[i] + pOffset<br />
y = yPosV[i]<br />
pWidth = iVerW<br />
pHeight = iVerH<br />
<br />
# Can't have these cluttering up the page<br />
scribus.deleteObject(tempImage)<br />
<br />
# Now we create the REAL image object placed appropriately<br />
f = scribus.createImage(x, y, pWidth, pHeight)<br />
<br />
# and load the image<br />
scribus.loadImage(sourceDirectory+imagedir + '/' + D[imageCount], f)<br />
<br />
# this time when we scale the image, we do it proportionally<br />
scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=f)<br />
<br />
# Lpic is the label for each picture, the position is the same for all <br />
# image orientations and the labels are centered under the pictures.<br />
<br />
# Create the text frame.<br />
Lpic = scribus.createText(xPosH[i] + pOffset, yPosV[i] + iVerH + labelGap, iHorW, labelH)<br />
<br />
# populate with the file name<br />
scribus.setText(D[imageCount], Lpic)<br />
<br />
# and format as desired<br />
scribus.setTextAlignment(scribus.ALIGN_CENTERED, Lpic)<br />
scribus.setFont(labelFont, Lpic)<br />
scribus.setFontSize(labelFS, Lpic)<br />
#scribus.setFillColor("White", Lpic)<br />
<br />
# increment the image count<br />
imageCount += 1<br />
<br />
# Now the page number<br />
<br />
# Create a text frame<br />
pNum = scribus.createText(pNumX, pNumY, pNumW, pNumH)<br />
<br />
# Put the page number in it and format<br />
pageNumberPrint = pageNumber + (int(firstPageNumber)-1)<br />
scribus.setText(`pageNumberPrint`, pNum)<br />
if imageCount < len(D):<br />
scribus.setTextAlignment(scribus.ALIGN_RIGHT, pNum)<br />
else:<br />
scribus.setTextAlignment(scribus.ALIGN_LEFT, pNum)<br />
scribus.setFont(labelFont, pNum)<br />
scribus.setFontSize(pNumFS, pNum)<br />
#scribus.setFillColor("White", pNum)<br />
<br />
# Finally, we increment the page number<br />
pageNumber += 1<br />
scribus.setRedraw(1)<br />
scribus.redrawAll()<br />
<br />
else:<br />
result = scribus.messageBox ('Not Found','No Images found with\n this search selection',scribus.BUTTON_OK)<br />
<br />
scribus.setRedraw(1)<br />
scribus.redrawAll()<br />
<br />
scribus.statusMessage("Saving File as "+outputDirectory+imagedir)<br />
#result = scribus.messageBox("Save", "Saving SLA File as: "+outputDirectory+imagedir+".sla")<br />
scribus.saveDocAs(outputDirectory+imagedir+".sla")<br />
<br />
scribus.statusMessage("Saving PDF File as "+outputDirectory+imagedir)<br />
pdfExport = scribus.PDFfile()<br />
pdfExport.info = outputDirectory+imagedir+".pdf"<br />
pNum = 1<br />
PDFPages = []<br />
while pNum < pageNumber:<br />
PDFPages.append(pNum)<br />
pNum += 1<br />
pdfExport.pages = PDFPages<br />
pdfExport.file = outputDirectory+imagedir+".pdf"<br />
pdfExport.save()<br />
<br />
scribus.closeDoc()<br />
<br />
scribus.statusMessage("")<br />
scribus.progressReset()<br />
<br />
</nowiki></pre></div>Hhartleyhttps://wiki.scribus.net/wiki/index.php?title=Automatic_import_of_images:_Multiple_image_directories&diff=23020Automatic import of images: Multiple image directories2010-12-02T18:22:39Z<p>Hhartley: Added a word of caution</p>
<hr />
<div>Starting with the script found on the page [[Automatic import of images: Versions not requiring Tkinter#album_letter_2.py]], I have created a new script that will take a collection of image directories and create 12-images-per-page documents from each of them in turn, save the documents and generate PDF files from each.<br />
<br />
The initial input and output directories are specified in the code and will need to be changed based on your own configuration. They are defined on lines 6 and 7. There are many other settings that may be adjusted but this should work well enough as a starting point.<br />
<br />
The basic idea here is to go through the source directory and gather all the sub-directory names. Then, go through each of those sub-directories and generate a document with the images found there, 12 per page. The document places the sub-directory name at the top of each page, arranges the images in four rows of three images with the file names centered under each. Page numbers are added. Since I print these documents double sided, the page numbers move from side to side and the entire page contents are shifted a little to the right (odd numbered pages) or the left (even numbered pages). Each gallery gets its own file.<br />
<br />
Once generated, an SLA file is saved in the outputDirectory specified on line 7. Then, a PDF is generated with all pages and saved to the same location. Both files are named the same as the image sub-directory but with .sla and .pdf extensions respectively.<br />
<br />
Caution: if you have directories with too many or very large image files, this can take a long while to run. Documents for directories with a dozen or two images of the appropriate size are created, saved, and exported to PDF in a matter of seconds. Documents for directories with images much larger than necessary or with more than a couple hundred images can take many minutes to be created. Since the images are printed at just over 1.4 by 2.1 inches, even at 300 dpi they will only need to be 420 by 633 pixels and you can probably get away with less. I would be cautious running this script on directories with lots of images or those copied directly from your digital camera.<br />
<br />
Considerable credit and thanks to Gregory Pittman, who wrote the original script on which this is based.<br />
<br />
<pre><nowiki><br />
#!/usr/bin/env python<br />
<br />
"""<br />
This is contact-sheet.py. This script will load the images from any number<br />
of directories, creating a new document of US Letter size from each directory.<br />
<br />
AUTHOR: Henry Hartley, December 2, 2010, with thanks to Gregory Pittman<br />
<br />
LICENSE: This program is free software; you can redistribute it and/or modify <br />
it under the terms of the GNU General Public License as published by the Free <br />
Software Foundation; either version 2 of the License, or (at your option) any <br />
later version.<br />
<br />
http://wiki.scribus.net/index.php/Automatic_import_of_images:_Multiple_image_directories<br />
<br />
"""<br />
<br />
import scribus<br />
import os<br />
<br />
sourceDirectory = "C:/temp/photographs/images/"<br />
outputDirectory = "C:/temp/photographs/contact_sheets/"<br />
<br />
filetype = []<br />
dicttype = {'j':'.jpg','p':'.png','t':'.tif','g':'.gif','P':'.pdf'}<br />
Dicttype = {'j':'.JPG','p':'.PNG','t':'.TIF','g':'.GIF','P':'.PDF'}<br />
<br />
firstPageNumber = '1'<br />
imagetype = 'jptgP'<br />
labelFont = 'Garamond Regular'<br />
<br />
for t in imagetype[0:]:<br />
filetype.append(dicttype[t])<br />
filetype.append(Dicttype[t])<br />
<br />
# All of these numbers can be adjusted but what is here seems to work pretty well<br />
<br />
marginX = 36<br />
marginY = 36<br />
<br />
# Image height and width<br />
iHorW = 152<br />
iVerW = 101<br />
iVerH = iHorW<br />
iHorH = iVerW<br />
<br />
# Gap sizes and page offsets<br />
gapW = 24<br />
gapH = 21<br />
xOffset = 36<br />
yOffset = 24<br />
<br />
# Page title text frame<br />
titleFS = 12<br />
titleX = marginX<br />
titleY = marginY<br />
titleW = iHorW + iHorW + gapW + iHorW + gapW<br />
titleH = titleFS * 2<br />
<br />
# Image label text frame<br />
# Height is enough to allow a second line of text if desired.<br />
labelGap = 0<br />
labelFS = 7<br />
labelH = labelFS * 3<br />
<br />
# Page number text frame<br />
pNumFS = 8<br />
pNumY = 759<br />
pNumXt = 2<br />
pNumW = 18<br />
pNumH = pNumFS * 1.5<br />
<br />
H2V = int((iHorW-iHorH)/2)<br />
V2H = int((iVerH-iVerW)/2)<br />
<br />
# It's quite likely that these longs lists could be replaced by a formula.<br />
# If anyone has the time to do that, it would probably make this script easier<br />
# to maintain.<br />
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)]<br />
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]<br />
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]<br />
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)]<br />
imgID = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]<br />
imgRow = 3<br />
imagedir = ""<br />
<br />
dirCount = 0<br />
dir = os.listdir(sourceDirectory)<br />
DIR = []<br />
for file in dir:<br />
#result = scribus.messageBox("Directory", "File: "+file)<br />
if os.path.isdir(sourceDirectory+file):<br />
DIR.append(file)<br />
dirCount += 1<br />
DIR.sort()<br />
<br />
#result = scribus.messageBox("Directory Count", "There were "+str(dirCount)+" directories added to the array")<br />
<br />
for imagedir in DIR:<br />
#result = scribus.messageBox("Directory", "The directory about to be processed is: "+imagedir)<br />
d = os.listdir(sourceDirectory+imagedir)<br />
D = []<br />
for file in d:<br />
for format in filetype:<br />
if file.endswith(format):<br />
D.append(file)<br />
D.sort()<br />
<br />
gallerytitle = imagedir<br />
<br />
imageCount = 0<br />
pageNumber = 1<br />
scribus.progressTotal(len(D))<br />
if len(D) > 0:<br />
if scribus.newDoc(scribus.PAPER_LETTER, (marginX, marginX, marginY, marginY),scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.NOFACINGPAGES, scribus.FIRSTPAGERIGHT):<br />
while imageCount < len(D):<br />
if imageCount > 0:<br />
scribus.newPage(-1)<br />
<br />
# Here is where we're loading images into the page, four, six, or twelve at a time, then go back up for a newPage<br />
if pageNumber % 2 == 0:<br />
pOffset = 0<br />
pNumX = xPosH[0]<br />
else:<br />
pOffset = xOffset<br />
pNumX = xPosH[pNumXt] + iHorW + pOffset - pNumW<br />
<br />
# L is the frame at the top of each page showing the gallery title (read in above)<br />
L = scribus.createText(titleX + pOffset, titleY, titleW, titleH)<br />
scribus.setText(gallerytitle, L)<br />
scribus.setTextAlignment(scribus.ALIGN_CENTERED, L)<br />
scribus.setFont(labelFont, L)<br />
scribus.setFontSize(titleFS, L)<br />
<br />
for i in imgID:<br />
if imageCount < len(D):<br />
<br />
scribus.statusMessage("Placing image " + D[imageCount] + " in document (" + `imageCount` + " of " + `len(D)` + ")")<br />
scribus.progressSet(imageCount)<br />
<br />
# Create a temporary image object. Size and location are irrelivant<br />
tempImage = scribus.createImage(10, 10, 10, 10)<br />
<br />
# Populate that object with your image<br />
scribus.loadImage(sourceDirectory+imagedir + '/' + D[imageCount], tempImage)<br />
<br />
# Scale the image but NOT proportionally<br />
scribus.setScaleImageToFrame(scaletoframe=1, proportional=0, name=tempImage)<br />
<br />
# Use getImageScale to get the relative scaling in the x and y directions<br />
imgx,imgy = scribus.getImageScale(tempImage)<br />
<br />
# If imgx < imgy, you have an horizontal image, otherwise, <br />
# a vertical (or square) image. <br />
if imgx < imgy:<br />
x = xPosH[i] + pOffset<br />
y = yPosH[i]<br />
pWidth = iHorW<br />
pHeight = iHorH<br />
else:<br />
x = xPosV[i] + pOffset<br />
y = yPosV[i]<br />
pWidth = iVerW<br />
pHeight = iVerH<br />
<br />
# Can't have these cluttering up the page<br />
scribus.deleteObject(tempImage)<br />
<br />
# Now we create the REAL image object placed appropriately<br />
f = scribus.createImage(x, y, pWidth, pHeight)<br />
<br />
# and load the image<br />
scribus.loadImage(sourceDirectory+imagedir + '/' + D[imageCount], f)<br />
<br />
# this time when we scale the image, we do it proportionally<br />
scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=f)<br />
<br />
# Lpic is the label for each picture, the position is the same for all <br />
# image orientations and the labels are centered under the pictures.<br />
<br />
# Create the text frame.<br />
Lpic = scribus.createText(xPosH[i] + pOffset, yPosV[i] + iVerH + labelGap, iHorW, labelH)<br />
<br />
# populate with the file name<br />
scribus.setText(D[imageCount], Lpic)<br />
<br />
# and format as desired<br />
scribus.setTextAlignment(scribus.ALIGN_CENTERED, Lpic)<br />
scribus.setFont(labelFont, Lpic)<br />
scribus.setFontSize(labelFS, Lpic)<br />
#scribus.setFillColor("White", Lpic)<br />
<br />
# increment the image count<br />
imageCount += 1<br />
<br />
# Now the page number<br />
<br />
# Create a text frame<br />
pNum = scribus.createText(pNumX, pNumY, pNumW, pNumH)<br />
<br />
# Put the page number in it and format<br />
pageNumberPrint = pageNumber + (int(firstPageNumber)-1)<br />
scribus.setText(`pageNumberPrint`, pNum)<br />
if imageCount < len(D):<br />
scribus.setTextAlignment(scribus.ALIGN_RIGHT, pNum)<br />
else:<br />
scribus.setTextAlignment(scribus.ALIGN_LEFT, pNum)<br />
scribus.setFont(labelFont, pNum)<br />
scribus.setFontSize(pNumFS, pNum)<br />
#scribus.setFillColor("White", pNum)<br />
<br />
# Finally, we increment the page number<br />
pageNumber += 1<br />
scribus.setRedraw(1)<br />
scribus.redrawAll()<br />
<br />
else:<br />
result = scribus.messageBox ('Not Found','No Images found with\n this search selection',scribus.BUTTON_OK)<br />
<br />
scribus.setRedraw(1)<br />
scribus.redrawAll()<br />
<br />
scribus.statusMessage("Saving File as "+outputDirectory+imagedir)<br />
#result = scribus.messageBox("Save", "Saving SLA File as: "+outputDirectory+imagedir+".sla")<br />
scribus.saveDocAs(outputDirectory+imagedir+".sla")<br />
<br />
scribus.statusMessage("Saving PDF File as "+outputDirectory+imagedir)<br />
pdfExport = scribus.PDFfile()<br />
pdfExport.info = outputDirectory+imagedir+".pdf"<br />
pNum = 1<br />
PDFPages = []<br />
while pNum < pageNumber:<br />
PDFPages.append(pNum)<br />
pNum += 1<br />
pdfExport.pages = PDFPages<br />
pdfExport.file = outputDirectory+imagedir+".pdf"<br />
pdfExport.save()<br />
<br />
scribus.closeDoc()<br />
<br />
scribus.statusMessage("")<br />
scribus.progressReset()<br />
<br />
</nowiki></pre></div>Hhartleyhttps://wiki.scribus.net/wiki/index.php?title=Automatic_import_of_images:_Versions_not_requiring_Tkinter&diff=23019Automatic import of images: Versions not requiring Tkinter2010-12-02T18:03:47Z<p>Hhartley: /* album_letter_2.py */ add link to another script variant</p>
<hr />
<div>{{Scripting Index}}<br />
<br />
==scribalbum_letter.py==<br />
<br />
Link to: [[Automatic import of images from a directory using a script]]<br />
<br />
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.<br />
<br />
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.<br />
<br />
Some rewriting was done so that this works with Scribus version 1.3.5svn, and the default font was changed to DejaVu Sans &ndash; if you want to use a different one, look for the <tt>labelFont</tt> variable assignment. This version of scribalbum_letter also works with Scribus 1.3.3.x.<br />
<br />
<pre><br />
#!/usr/bin/env python<br />
<br />
"""<br />
This is scribalbum_letter.py. This script will load the images from a<br />
directory, creating a new document of US Letter size.<br />
<br />
USAGE: It is probably better not to already have any document in Scribus,<br />
since memory usage can become intense when a large number of images is<br />
used. <br />
You are first presented with a dialog to choose either 4 or 6 images per page.<br />
Next select a directory where your images are located. Finally, select the <br />
types of image files, using the code you see in the last dialog. <br />
NOTE: If you choose PDF, only the first page will be imported, and the PDF <br />
will be rasterized.<br />
<br />
AUTHOR: Gregory Pittman Original version: 2005.02.13, this version: 2008.07.23<br />
<br />
LICENSE: This program is free software; you can redistribute it and/or modify <br />
it under the terms of the GNU General Public License as published by the Free <br />
Software Foundation; either version 2 of the License, or (at your option) any <br />
later version.<br />
<br />
"""<br />
<br />
import scribus<br />
import os<br />
<br />
filetype = []<br />
dicttype = {'j':'.jpg','p':'.png','t':'.tif','g':'.gif','P':'.pdf'}<br />
Dicttype = {'j':'.JPG','p':'.PNG','t':'.TIF','g':'.GIF','P':'.PDF'}<br />
nrimages = '0'<br />
while (nrimages != '4') and (nrimages != '6'):<br />
nrimages = scribus.valueDialog('Pictures','- US Letter Paper -\n Four or Six Images per Page?\nChange to 6 as desired','4')<br />
imagedir = scribus.fileDialog('Select Image Directory','Directories',isdir=True)<br />
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')<br />
for t in imagetype[0:]:<br />
filetype.append(dicttype[t])<br />
filetype.append(Dicttype[t])<br />
d = os.listdir(imagedir)<br />
D = []<br />
for file in d:<br />
for format in filetype:<br />
if file.endswith(format):<br />
D.append(file)<br />
D.sort()<br />
labelFont="DejaVu Sans Book"<br />
<br />
# When 4 pics per page, coords are: (15, 42),(310, 187), (15, 388), (310, 533)<br />
# When 6 pics per page: (15, 42),(310, 42), (15, 290), (310, 290),(15,533),(310,533)<br />
if nrimages == '4':<br />
xpos = [15, 310, 15, 310] <br />
ypos = [42, 187, 388, 533]<br />
if nrimages == '6':<br />
xpos = [15, 310, 15, 310, 15, 310]<br />
ypos = [42, 42, 290, 290, 533, 533]<br />
# This proportion is right for photographs from my digital camera<br />
pwidth = 288<br />
pheight = 193<br />
imagecount = 0<br />
#framecount = 0<br />
if len(D) > 0:<br />
if scribus.newDoc(scribus.PAPER_LETTER, (10,10,20,20),scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.NOFACINGPAGES, scribus.FIRSTPAGERIGHT):<br />
while imagecount < len(D):<br />
if imagecount > 0:<br />
scribus.newPage(-1)<br />
framecount = 0<br />
# L is the frame at the top of each page showing the directory name<br />
L = scribus.createText(15, 20, 200, 20)<br />
scribus.setText("Dir: " + imagedir, L)<br />
scribus.setTextAlignment(scribus.ALIGN_LEFT, L)<br />
scribus.setFont(labelFont, L)<br />
scribus.setFontSize(10, L)<br />
# Here is where we're loading images into the page, four at a time, then go back up for a newPage<br />
for x,y in zip(xpos,ypos):<br />
if imagecount < len(D):<br />
f = scribus.createImage(x, y, pwidth, pheight)<br />
scribus.loadImage(imagedir + '/' + D[imagecount], f)<br />
scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=f)<br />
lenfilename = len(D[imagecount])<br />
Lpiclen = int(5.3 * lenfilename)<br />
# Lpic is the label for each picture, with position and length adjusted<br />
# according to the text length, so if you change the font or its size,<br />
# you may need to adjust this only approximate calculation.<br />
Lpic = scribus.createText(x, y + 193, Lpiclen, 15)<br />
scribus.setText(D[imagecount], Lpic)<br />
scribus.setTextAlignment(scribus.ALIGN_RIGHT, Lpic)<br />
scribus.setFont(labelFont, Lpic)<br />
scribus.setFontSize(8, Lpic)<br />
scribus.setFillColor("White", Lpic)<br />
imagecount += 1<br />
<br />
scribus.setRedraw(1)<br />
scribus.redrawAll()<br />
<br />
else:<br />
result = scribus.messageBox ('Not Found','No Images found with\n this search selection',scribus.BUTTON_OK)<br />
</pre><br />
<br />
==scribalbum_a4.py==<br />
<br />
This is the version that puts 8 images on A4 paper, with little extra space. Usage is as above.<br />
<br />
<pre><br />
<nowiki><br />
#!/usr/bin/env python<br />
<br />
# File: scribalbum_a4.py<br />
# originally 2005.02.13 Gregory Pittman<br />
# this version 2006.03.17 does without Tkinter<br />
# Uses valueDialog() for data entry of directory name<br />
# and also mnemonics for image types, j=jpg, and so on.<br />
# Also searches for uppercase equivalents.<br />
# Makes a new document<br />
<br />
from scribus import *<br />
import os<br />
<br />
filetype = []<br />
dicttype = {'j':'.jpg','p':'.png','t':'.tif','g':'.gif','P':'.pdf','J':'.jpeg'}<br />
Dicttype = {'j':'.JPG','p':'.PNG','t':'.TIF','g':'.GIF','P':'.PDF','J':'.JPEG'}<br />
<br />
imagedir = valueDialog('Images','Enter the Image Directory')<br />
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')<br />
for t in imagetype[0:]:<br />
filetype.append(dicttype[t])<br />
filetype.append(Dicttype[t])<br />
<br />
D=[]<br />
d = os.listdir(imagedir)<br />
for file in d:<br />
for format in filetype:<br />
if file.endswith(format):<br />
D.append(file)<br />
D.sort()<br />
labelFont = "DejaVu Sans"<br />
# There are 8 pictures per page; xpos and ypos are the x,y coord of the upper left corners<br />
xpos = (25, 321) <br />
ypos = (42, 236, 430, 624)<br />
# This proportion is right for photographs (at least for my digital Olympus)<br />
pwidth = 250<br />
pheight = 187<br />
imagecount = 0<br />
if len(D) > 0:<br />
if newDoc(PAPER_A4, (10,10,20,20),PORTRAIT, 1, UNIT_POINTS, NOFACINGPAGES, FIRSTPAGERIGHT):<br />
while imagecount < len(D):<br />
if imagecount > 0:<br />
newPage(-1)<br />
# L is the frame at the top of each page showing the directory name<br />
L = createText(15, 20, 200, 20)<br />
setText("Dir: " + imagedir, L)<br />
setTextAlignment(ALIGN_LEFT, L)<br />
setFont(labelFont, L)<br />
setFontSize(10, L)<br />
# Here is where we're loading images into the page, eight at a time, then go back up for a newPage<br />
for yframe in ypos:<br />
for xframe in xpos:<br />
if imagecount < len(D):<br />
f = createImage(xframe, yframe, pwidth, pheight)<br />
loadImage(imagedir + '/' + D[imagecount], f)<br />
setScaleImageToFrame(scaletoframe=1, proportional=1, name=f)<br />
lenfilename = len(D[imagecount])<br />
Lpiclen = int(5.3 * lenfilename)<br />
# Lpic is the label for each picture, with position and length adjusted according to the text length<br />
# so if you change in font or its size, you may need to adjust this only approximate calculation<br />
Lpic = createText(xframe + (250 - Lpiclen), yframe + 172, Lpiclen, 15)<br />
setText(D[imagecount], Lpic)<br />
setTextAlignment(ALIGN_RIGHT, Lpic)<br />
setFont(labelFont, Lpic)<br />
setFontSize(8, Lpic)<br />
setFillColor("White", Lpic)<br />
imagecount = imagecount + 1<br />
<br />
setRedraw(1)<br />
redrawAll()<br />
<br />
else:<br />
result = messageBox ('Not Found','No Images found with\n this search selection',BUTTON_OK)<br />
<br />
</nowiki><br />
</pre><br />
<br />
== album_letter_2.py ==<br />
<br />
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.<br />
<br />
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]].<br />
<br />
<pre><nowiki><br />
#!/usr/bin/env python<br />
<br />
"""<br />
This is scribalbum_letter.py. This script will load the images from a<br />
directory, creating a new document of US Letter size.<br />
<br />
USAGE: It is probably better not to already have any document in Scribus,<br />
since memory usage can become intense when a large number of images is<br />
used.<br />
<br />
You are first presented with a dialog to choose either 4 or 6 images per page.<br />
Next select a directory where your images are located. Finally, select the <br />
types of image files, using the code you see in the last dialog. <br />
NOTE: If you choose PDF, only the first page will be imported, and the PDF <br />
will be rasterized.<br />
<br />
AUTHOR: Gregory Pittman Original version: 2005.02.13, this version: 2008.07.23<br />
<br />
LICENSE: This program is free software; you can redistribute it and/or modify <br />
it under the terms of the GNU General Public License as published by the Free <br />
Software Foundation; either version 2 of the License, or (at your option) any <br />
later version.<br />
<br />
http://wiki.scribus.net/index.php/Automatic_import_of_images:_Versions_not_requiring_Tkinter<br />
<br />
========================================================================<br />
<br />
Modifications by Henry Hartley - September, 2009:<br />
<br />
* allow user to specify 4, 6, or 12 images per page, selected at run time<br />
* changed font to Garamond Regular but provide a dialog for the user to change this at run time<br />
* Image are arranged in one of these ways:<br />
<br />
1 2 1 2 1 2 3<br />
3 4 3 4 4 5 6<br />
5 6 7 8 9<br />
10 11 12<br />
<br />
* figure out if images are landscape or portrait and adjust frame accordingly<br />
* center labels under images<br />
* offset page somewhat for 3-hole punch when printed double sided<br />
* replaced dir at top of all pages to a title, specified at run time<br />
* added page numbers (alternating corners for double sided printing)<br />
* the Scribus progress indicator and status line show how many files have<br />
been imported<br />
<br />
Note: 8.5 by 11 inch page is 612 by 792 points<br />
<br />
If you convert all images to a size close to what is needed by this script <br />
before running it then the memory requirements are reduced. The goal is to<br />
get an image that is the same size or only slightly larger than the image <br />
frame at 300dpi. Depending upon the number of pictures per page, this will <br />
be one of the following sizes:<br />
<br />
4 per page: 758 by 1137 pixels (182 by 273 points at 300dpi)<br />
6 per page: 608 by 912 pixels (146 by 219 points at 300dpi)<br />
12 per page: 421 by 633 pixels (101 by 152 points at 300dpi)<br />
<br />
One way to do this is to create a sub-directory under your image directory <br />
called "small" and then running a perl one-liner as shown below (assuming <br />
both Perl and ImageMagick are installed, of course).<br />
<br />
Note that the double backslash after "small" is required on MS Windows.<br />
Replace with a forward slash on Linux. The 37% used here works just about <br />
right when resizing images starting life as the 2048 by 3072 pixel images <br />
produced by my EOS D10 camera. Adjust accordingly. Fractional percentages <br />
are allowed.<br />
<br />
perl -e "((print qq|$_\n|) && system(qq|convert -resample 300 $_ -resize 50% small\\$_|)) foreach (glob(qq|*.jpg|))"<br />
<br />
------------------------------------------------------------------------<br />
<br />
A few minor things:<br />
<br />
After running, I export to PDF. Scribus reports Text Overflow errors on<br />
many (or possibly all) of the text fields. These errors, it seems, may <br />
safely be ignored.<br />
<br />
Depending on your requirements, you may want to change the Compression<br />
Quality setting in the PDF export dialog to something other than Maximum.<br />
<br />
While this script will run on a large number of images, it slows down as<br />
it runs (on my relatively modest hardware) and you may need to break up<br />
large collections into parts.<br />
<br />
<br />
"""<br />
<br />
import scribus<br />
import os<br />
<br />
filetype = []<br />
dicttype = {'j':'.jpg','p':'.png','t':'.tif','g':'.gif','P':'.pdf'}<br />
Dicttype = {'j':'.JPG','p':'.PNG','t':'.TIF','g':'.GIF','P':'.PDF'}<br />
nrimages = '0'<br />
<br />
while (nrimages != '4') and (nrimages != '6') and (nrimages != '12') and (nrimages != 'c'):<br />
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')<br />
<br />
imagedir = scribus.fileDialog('Select Image Directory','Directories',isdir=True)<br />
<br />
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')<br />
<br />
gallerytitle = scribus.valueDialog('Gallery Title','Enter the title you want to appear on all pages','')<br />
<br />
labelFont = scribus.valueDialog('Font for Text','Enter the name of the font you would like to use throughout your document','Garamond Regular')<br />
<br />
for t in imagetype[0:]:<br />
filetype.append(dicttype[t])<br />
filetype.append(Dicttype[t])<br />
d = os.listdir(imagedir)<br />
D = []<br />
for file in d:<br />
for format in filetype:<br />
if file.endswith(format):<br />
D.append(file)<br />
D.sort()<br />
<br />
# All of these numbers can be adjusted but what is here seems to work pretty well<br />
# If you would like to add new a new page size or layout, add a new set of values<br />
# in this section rather than replacing an existing set.<br />
<br />
if nrimages == '4':<br />
marginX = 24<br />
marginY = 24<br />
<br />
# Image height and width<br />
iHorW = 273<br />
iVerW = 182<br />
iVerH = iHorW<br />
iHorH = iVerW<br />
<br />
# Gap sizes and page offsets<br />
gapW = 6<br />
gapH = 73<br />
xOffset = 12<br />
yOffset = 58<br />
<br />
# Page title text frame<br />
titleFS = 18<br />
titleX = marginX<br />
titleY = marginY<br />
titleW = iHorW + iHorW + gapW<br />
titleH = titleFS * 2<br />
<br />
# Image label text frame<br />
# Height is enough to allow a second line of text if desired.<br />
labelGap = 6<br />
labelFS = 12<br />
labelH = labelFS * 3<br />
<br />
# Page number text frame<br />
pNumFS = 12<br />
pNumY = 759<br />
pNumXt = 1<br />
pNumW = 18<br />
pNumH = pNumFS * 1.5<br />
<br />
H2V = int((iHorW-iHorH)/2)<br />
V2H = int((iVerH-iVerW)/2)<br />
<br />
xPosH = [marginX, marginX + iHorW + gapW, marginX, marginX + iHorW + gapW]<br />
yPosH = [marginY + yOffset + V2H, marginY + yOffset + V2H, marginY + yOffset + iVerH + gapH + V2H, marginY + yOffset + iVerH + gapH + V2H]<br />
xPosV = [marginX + H2V, marginX + iHorW + gapW + H2V, marginX + H2V, marginX + iHorW + gapW + H2V]<br />
yPosV = [marginY + yOffset, marginY + yOffset, marginY + yOffset + iVerH + gapH, marginY + yOffset + iVerH + gapH]<br />
imgID = [0, 1, 2, 3]<br />
imgRow = 2<br />
<br />
<br />
<br />
if nrimages == '6':<br />
marginX = 48<br />
marginY = 18<br />
<br />
# Image height and width<br />
iHorW = 219<br />
iVerW = 146<br />
iVerH = iHorW<br />
iHorH = iVerW<br />
<br />
# Gap sizes and page offsets<br />
gapW = 30<br />
gapH = 18<br />
xOffset = 48<br />
yOffset = 24<br />
<br />
# Page title text frame<br />
titleFS = 12<br />
titleX = marginX<br />
titleY = marginY<br />
titleW = iHorW + gapW + iHorW<br />
titleH = titleFS * 2<br />
<br />
# Image label text frame<br />
# Height is enough to allow a second line of text if desired.<br />
labelGap = 0<br />
labelFS = 7<br />
labelH = labelFS * 3<br />
<br />
# Page number text frame<br />
pNumFS = 8<br />
pNumY = 759<br />
pNumXt = 1<br />
pNumW = 18<br />
pNumH = pNumFS * 1.5<br />
<br />
H2V = int((iHorW-iHorH)/2)<br />
V2H = int((iVerH-iVerW)/2)<br />
<br />
# It's quite likely that these longs lists could be replaced by a formula.<br />
# If anyone has the time to do that, it would probably make this script easier<br />
# to maintain.<br />
xPosH = [marginX, marginX + iHorW + gapW, marginX, marginX + iHorW + gapW, marginX, marginX + iHorW + gapW]<br />
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]<br />
xPosV = [marginX + H2V, marginX + iHorW + gapW + H2V, marginX + H2V, marginX + iHorW + gapW + H2V, marginX + H2V, marginX + iHorW + gapW + H2V]<br />
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)]<br />
imgID = [0, 1, 2, 3, 4, 5]<br />
imgRow = 2<br />
<br />
<br />
<br />
if nrimages == '12':<br />
marginX = 36<br />
marginY = 36<br />
<br />
# Image height and width<br />
iHorW = 152<br />
iVerW = 101<br />
iVerH = iHorW<br />
iHorH = iVerW<br />
<br />
# Gap sizes and page offsets<br />
gapW = 24<br />
gapH = 21<br />
xOffset = 36<br />
yOffset = 24<br />
<br />
# Page title text frame<br />
titleFS = 12<br />
titleX = marginX<br />
titleY = marginY<br />
titleW = iHorW + iHorW + gapW + iHorW + gapW<br />
titleH = titleFS * 2<br />
<br />
# Image label text frame<br />
# Height is enough to allow a second line of text if desired.<br />
labelGap = 0<br />
labelFS = 7<br />
labelH = labelFS * 3<br />
<br />
# Page number text frame<br />
pNumFS = 8<br />
pNumY = 759<br />
pNumXt = 2<br />
pNumW = 18<br />
pNumH = pNumFS * 1.5<br />
<br />
H2V = int((iHorW-iHorH)/2)<br />
V2H = int((iVerH-iVerW)/2)<br />
<br />
# It's quite likely that these longs lists could be replaced by a formula.<br />
# If anyone has the time to do that, it would probably make this script easier<br />
# to maintain.<br />
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)]<br />
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]<br />
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]<br />
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)]<br />
imgID = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]<br />
imgRow = 3<br />
<br />
<br />
# EXTRA CATEGORY - By putting this in I have a place to put temporary numbers <br />
# for one of a kind collections. For instance, the parameters above assume that<br />
# images will have the 3:2 aspect ratio of 35mm film or most digital camera <br />
# images. The numbers used here are slightly modified to work with images scanned <br />
# from 4x5 inch negatives.<br />
<br />
if nrimages == 'c':<br />
marginX = 36<br />
marginY = 48<br />
<br />
# Image height and width<br />
iHorW = 125<br />
iVerW = 100<br />
iVerH = iHorW<br />
iHorH = iVerW<br />
<br />
# Gap sizes and page offsets<br />
gapW = 60<br />
gapH = 45<br />
xOffset = 39<br />
yOffset = 36<br />
<br />
# Page title text frame<br />
titleFS = 12<br />
titleX = marginX<br />
titleY = marginY<br />
titleW = iHorW + iHorW + gapW + iHorW + gapW<br />
titleH = titleFS * 2<br />
<br />
# Image label text frame<br />
# Height is enough to allow a second line of text if desired.<br />
labelGap = 0<br />
labelFS = 7<br />
labelH = labelFS * 3<br />
<br />
# Page number text frame<br />
pNumFS = 8<br />
pNumY = 759<br />
pNumXt = 2<br />
pNumW = 18<br />
pNumH = pNumFS * 1.5<br />
<br />
H2V = int((iHorW-iHorH)/2)<br />
V2H = int((iVerH-iVerW)/2)<br />
<br />
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)]<br />
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]<br />
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]<br />
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)]<br />
imgID = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]<br />
imgRow = 3<br />
<br />
imageCount = 0<br />
pageNumber = 1<br />
scribus.progressTotal(len(D))<br />
if len(D) > 0:<br />
if scribus.newDoc(scribus.PAPER_LETTER, (marginX, marginX, marginY, marginY),scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.NOFACINGPAGES, scribus.FIRSTPAGERIGHT):<br />
while imageCount < len(D):<br />
if imageCount > 0:<br />
scribus.newPage(-1)<br />
<br />
# Here is where we're loading images into the page, four, six, or twelve at a time, then go back up for a newPage<br />
if pageNumber % 2 == 0:<br />
pOffset = 0<br />
pNumX = xPosH[0]<br />
else:<br />
pOffset = xOffset<br />
pNumX = xPosH[pNumXt] + iHorW + pOffset - pNumW<br />
<br />
# L is the frame at the top of each page showing the gallery title (read in above)<br />
L = scribus.createText(titleX + pOffset, titleY, titleW, titleH)<br />
scribus.setText(gallerytitle, L)<br />
scribus.setTextAlignment(scribus.ALIGN_CENTERED, L)<br />
scribus.setFont(labelFont, L)<br />
scribus.setFontSize(titleFS, L)<br />
<br />
for i in imgID:<br />
if imageCount < len(D):<br />
<br />
scribus.statusMessage("Placing image " + D[imageCount] + " in document (" + `imageCount` + " of " + `len(D)` + ")")<br />
scribus.progressSet(imageCount)<br />
<br />
# Create a temporary image object. Size and location are irrelivant<br />
tempImage = scribus.createImage(10, 10, 10, 10)<br />
<br />
# Populate that object with your image<br />
scribus.loadImage(imagedir + '/' + D[imageCount], tempImage)<br />
<br />
# Scale the image but NOT proportionally<br />
scribus.setScaleImageToFrame(scaletoframe=1, proportional=0, name=tempImage)<br />
<br />
# Use getImageScale to get the relative scaling in the x and y directions<br />
imgx,imgy = scribus.getImageScale(tempImage)<br />
<br />
# If imgx < imgy, you have an horizontal image, otherwise, <br />
# a vertical (or square) image. <br />
if imgx < imgy:<br />
x = xPosH[i] + pOffset<br />
y = yPosH[i]<br />
pWidth = iHorW<br />
pHeight = iHorH<br />
else:<br />
x = xPosV[i] + pOffset<br />
y = yPosV[i]<br />
pWidth = iVerW<br />
pHeight = iVerH<br />
<br />
# Can't have these cluttering up the page<br />
scribus.deleteObject(tempImage)<br />
<br />
# Now we create the REAL image object placed appropriately<br />
f = scribus.createImage(x, y, pWidth, pHeight)<br />
<br />
# and load the image<br />
scribus.loadImage(imagedir + '/' + D[imageCount], f)<br />
<br />
# this time when we scale the image, we do it proportionally<br />
scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=f)<br />
<br />
# Lpic is the label for each picture, the position is the same for all <br />
# image orientations and the labels are centered under the pictures.<br />
<br />
# Create the text frame.<br />
Lpic = scribus.createText(xPosH[i] + pOffset, yPosV[i] + iVerH + labelGap, iHorW, labelH)<br />
<br />
# populate with the file name<br />
scribus.setText(D[imageCount], Lpic)<br />
<br />
# and format as desired<br />
scribus.setTextAlignment(scribus.ALIGN_CENTERED, Lpic)<br />
scribus.setFont(labelFont, Lpic)<br />
scribus.setFontSize(labelFS, Lpic)<br />
<br />
# increment the image count<br />
imageCount += 1<br />
<br />
# Now the page number<br />
<br />
# Create a text frame<br />
pNum = scribus.createText(pNumX, pNumY, pNumW, pNumH)<br />
<br />
# Put the page number in it and format<br />
scribus.setText(`pageNumber`, pNum)<br />
if imageCount < len(D):<br />
scribus.setTextAlignment(scribus.ALIGN_RIGHT, pNum)<br />
else:<br />
scribus.setTextAlignment(scribus.ALIGN_LEFT, pNum)<br />
scribus.setFont(labelFont, pNum)<br />
scribus.setFontSize(pNumFS, pNum)<br />
<br />
# Finally, we increment the page number<br />
pageNumber += 1<br />
scribus.setRedraw(1)<br />
scribus.redrawAll()<br />
<br />
else:<br />
result = scribus.messageBox ('Not Found','No Images found with\n this search selection',scribus.BUTTON_OK)<br />
<br />
scribus.setRedraw(1)<br />
scribus.redrawAll()<br />
<br />
scribus.statusMessage("")<br />
scribus.progressReset()<br />
<br />
</nowiki></pre></div>Hhartleyhttps://wiki.scribus.net/wiki/index.php?title=Automatic_import_of_images:_Multiple_image_directories&diff=23018Automatic import of images: Multiple image directories2010-12-02T18:01:11Z<p>Hhartley: Initial post</p>
<hr />
<div>Starting with the script found on the page [[Automatic import of images: Versions not requiring Tkinter#album_letter_2.py]], I have created a new script that will take a collection of image directories and create 12-images-per-page documents from each of them in turn, save the documents and generate PDF files from each.<br />
<br />
The initial input and output directories are specified in the code and will need to be changed based on your own configuration. They are defined on lines 6 and 7. There are many other settings that may be adjusted but this should work well enough as a starting point.<br />
<br />
The basic idea here is to go through the source directory and gather all the sub-directory names. Then, go through each of those sub-directories and generate a document with the images found there, 12 per page. The document places the sub-directory name at the top of each page, arranges the images in four rows of three images with the file names centered under each. Page numbers are added. Since I print these documents double sided, the page numbers move from side to side and the entire page contents are shifted a little to the right (odd numbered pages) or the left (even numbered pages). Each gallery gets its own file.<br />
<br />
Once generated, an SLA file is saved in the outputDirectory specified on line 7. Then, a PDF is generated with all pages and saved to the same location. Both files are named the same as the image sub-directory but with .sla and .pdf extensions respectively.<br />
<br />
Considerable credit goes to Gregory Pittman, who wrote the original script on which this is based.<br />
<br />
<pre><nowiki><br />
#!/usr/bin/env python<br />
<br />
"""<br />
This is contact-sheet.py. This script will load the images from any number<br />
of directories, creating a new document of US Letter size from each directory.<br />
<br />
AUTHOR: Henry Hartley, December 2, 2010, with thanks to Gregory Pittman<br />
<br />
LICENSE: This program is free software; you can redistribute it and/or modify <br />
it under the terms of the GNU General Public License as published by the Free <br />
Software Foundation; either version 2 of the License, or (at your option) any <br />
later version.<br />
<br />
http://wiki.scribus.net/index.php/Automatic_import_of_images:_Multiple_image_directories<br />
<br />
"""<br />
<br />
import scribus<br />
import os<br />
<br />
sourceDirectory = "C:/temp/photographs/images/"<br />
outputDirectory = "C:/temp/photographs/contact_sheets/"<br />
<br />
filetype = []<br />
dicttype = {'j':'.jpg','p':'.png','t':'.tif','g':'.gif','P':'.pdf'}<br />
Dicttype = {'j':'.JPG','p':'.PNG','t':'.TIF','g':'.GIF','P':'.PDF'}<br />
<br />
firstPageNumber = '1'<br />
imagetype = 'jptgP'<br />
labelFont = 'Garamond Regular'<br />
<br />
for t in imagetype[0:]:<br />
filetype.append(dicttype[t])<br />
filetype.append(Dicttype[t])<br />
<br />
# All of these numbers can be adjusted but what is here seems to work pretty well<br />
<br />
marginX = 36<br />
marginY = 36<br />
<br />
# Image height and width<br />
iHorW = 152<br />
iVerW = 101<br />
iVerH = iHorW<br />
iHorH = iVerW<br />
<br />
# Gap sizes and page offsets<br />
gapW = 24<br />
gapH = 21<br />
xOffset = 36<br />
yOffset = 24<br />
<br />
# Page title text frame<br />
titleFS = 12<br />
titleX = marginX<br />
titleY = marginY<br />
titleW = iHorW + iHorW + gapW + iHorW + gapW<br />
titleH = titleFS * 2<br />
<br />
# Image label text frame<br />
# Height is enough to allow a second line of text if desired.<br />
labelGap = 0<br />
labelFS = 7<br />
labelH = labelFS * 3<br />
<br />
# Page number text frame<br />
pNumFS = 8<br />
pNumY = 759<br />
pNumXt = 2<br />
pNumW = 18<br />
pNumH = pNumFS * 1.5<br />
<br />
H2V = int((iHorW-iHorH)/2)<br />
V2H = int((iVerH-iVerW)/2)<br />
<br />
# It's quite likely that these longs lists could be replaced by a formula.<br />
# If anyone has the time to do that, it would probably make this script easier<br />
# to maintain.<br />
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)]<br />
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]<br />
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]<br />
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)]<br />
imgID = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]<br />
imgRow = 3<br />
imagedir = ""<br />
<br />
dirCount = 0<br />
dir = os.listdir(sourceDirectory)<br />
DIR = []<br />
for file in dir:<br />
#result = scribus.messageBox("Directory", "File: "+file)<br />
if os.path.isdir(sourceDirectory+file):<br />
DIR.append(file)<br />
dirCount += 1<br />
DIR.sort()<br />
<br />
#result = scribus.messageBox("Directory Count", "There were "+str(dirCount)+" directories added to the array")<br />
<br />
for imagedir in DIR:<br />
#result = scribus.messageBox("Directory", "The directory about to be processed is: "+imagedir)<br />
d = os.listdir(sourceDirectory+imagedir)<br />
D = []<br />
for file in d:<br />
for format in filetype:<br />
if file.endswith(format):<br />
D.append(file)<br />
D.sort()<br />
<br />
gallerytitle = imagedir<br />
<br />
imageCount = 0<br />
pageNumber = 1<br />
scribus.progressTotal(len(D))<br />
if len(D) > 0:<br />
if scribus.newDoc(scribus.PAPER_LETTER, (marginX, marginX, marginY, marginY),scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.NOFACINGPAGES, scribus.FIRSTPAGERIGHT):<br />
while imageCount < len(D):<br />
if imageCount > 0:<br />
scribus.newPage(-1)<br />
<br />
# Here is where we're loading images into the page, four, six, or twelve at a time, then go back up for a newPage<br />
if pageNumber % 2 == 0:<br />
pOffset = 0<br />
pNumX = xPosH[0]<br />
else:<br />
pOffset = xOffset<br />
pNumX = xPosH[pNumXt] + iHorW + pOffset - pNumW<br />
<br />
# L is the frame at the top of each page showing the gallery title (read in above)<br />
L = scribus.createText(titleX + pOffset, titleY, titleW, titleH)<br />
scribus.setText(gallerytitle, L)<br />
scribus.setTextAlignment(scribus.ALIGN_CENTERED, L)<br />
scribus.setFont(labelFont, L)<br />
scribus.setFontSize(titleFS, L)<br />
<br />
for i in imgID:<br />
if imageCount < len(D):<br />
<br />
scribus.statusMessage("Placing image " + D[imageCount] + " in document (" + `imageCount` + " of " + `len(D)` + ")")<br />
scribus.progressSet(imageCount)<br />
<br />
# Create a temporary image object. Size and location are irrelivant<br />
tempImage = scribus.createImage(10, 10, 10, 10)<br />
<br />
# Populate that object with your image<br />
scribus.loadImage(sourceDirectory+imagedir + '/' + D[imageCount], tempImage)<br />
<br />
# Scale the image but NOT proportionally<br />
scribus.setScaleImageToFrame(scaletoframe=1, proportional=0, name=tempImage)<br />
<br />
# Use getImageScale to get the relative scaling in the x and y directions<br />
imgx,imgy = scribus.getImageScale(tempImage)<br />
<br />
# If imgx < imgy, you have an horizontal image, otherwise, <br />
# a vertical (or square) image. <br />
if imgx < imgy:<br />
x = xPosH[i] + pOffset<br />
y = yPosH[i]<br />
pWidth = iHorW<br />
pHeight = iHorH<br />
else:<br />
x = xPosV[i] + pOffset<br />
y = yPosV[i]<br />
pWidth = iVerW<br />
pHeight = iVerH<br />
<br />
# Can't have these cluttering up the page<br />
scribus.deleteObject(tempImage)<br />
<br />
# Now we create the REAL image object placed appropriately<br />
f = scribus.createImage(x, y, pWidth, pHeight)<br />
<br />
# and load the image<br />
scribus.loadImage(sourceDirectory+imagedir + '/' + D[imageCount], f)<br />
<br />
# this time when we scale the image, we do it proportionally<br />
scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=f)<br />
<br />
# Lpic is the label for each picture, the position is the same for all <br />
# image orientations and the labels are centered under the pictures.<br />
<br />
# Create the text frame.<br />
Lpic = scribus.createText(xPosH[i] + pOffset, yPosV[i] + iVerH + labelGap, iHorW, labelH)<br />
<br />
# populate with the file name<br />
scribus.setText(D[imageCount], Lpic)<br />
<br />
# and format as desired<br />
scribus.setTextAlignment(scribus.ALIGN_CENTERED, Lpic)<br />
scribus.setFont(labelFont, Lpic)<br />
scribus.setFontSize(labelFS, Lpic)<br />
#scribus.setFillColor("White", Lpic)<br />
<br />
# increment the image count<br />
imageCount += 1<br />
<br />
# Now the page number<br />
<br />
# Create a text frame<br />
pNum = scribus.createText(pNumX, pNumY, pNumW, pNumH)<br />
<br />
# Put the page number in it and format<br />
pageNumberPrint = pageNumber + (int(firstPageNumber)-1)<br />
scribus.setText(`pageNumberPrint`, pNum)<br />
if imageCount < len(D):<br />
scribus.setTextAlignment(scribus.ALIGN_RIGHT, pNum)<br />
else:<br />
scribus.setTextAlignment(scribus.ALIGN_LEFT, pNum)<br />
scribus.setFont(labelFont, pNum)<br />
scribus.setFontSize(pNumFS, pNum)<br />
#scribus.setFillColor("White", pNum)<br />
<br />
# Finally, we increment the page number<br />
pageNumber += 1<br />
scribus.setRedraw(1)<br />
scribus.redrawAll()<br />
<br />
else:<br />
result = scribus.messageBox ('Not Found','No Images found with\n this search selection',scribus.BUTTON_OK)<br />
<br />
scribus.setRedraw(1)<br />
scribus.redrawAll()<br />
<br />
scribus.statusMessage("Saving File as "+outputDirectory+imagedir)<br />
#result = scribus.messageBox("Save", "Saving SLA File as: "+outputDirectory+imagedir+".sla")<br />
scribus.saveDocAs(outputDirectory+imagedir+".sla")<br />
<br />
scribus.statusMessage("Saving PDF File as "+outputDirectory+imagedir)<br />
pdfExport = scribus.PDFfile()<br />
pdfExport.info = outputDirectory+imagedir+".pdf"<br />
pNum = 1<br />
PDFPages = []<br />
while pNum < pageNumber:<br />
PDFPages.append(pNum)<br />
pNum += 1<br />
pdfExport.pages = PDFPages<br />
pdfExport.file = outputDirectory+imagedir+".pdf"<br />
pdfExport.save()<br />
<br />
scribus.closeDoc()<br />
<br />
scribus.statusMessage("")<br />
scribus.progressReset()<br />
<br />
</nowiki></pre></div>Hhartleyhttps://wiki.scribus.net/wiki/index.php?title=Building_SVN_versions_with_CMake&diff=22083Building SVN versions with CMake2010-05-28T22:27:02Z<p>Hhartley: /* Success Stories */ Sorry, it wasn't CentOS, don't know what I was thinking.</p>
<hr />
<div>[[Category:Scribus_development]]<br />
<br />
After many years of using the autotools build system, the developers of Scribus have selected [http://www.cmake.org CMake] as a replacement system. It provides a much more flexible setup with a lot less complexity. It also provides compatibility with build tools on Linux and variants of Unix, Windows and Mac OSX.<br />
<br />
'''You must have CMake version &ge; 2.4.3 for best results. Older versions will fail.'''<br />
<br />
==Introduction: don't let it scare you off==<br />
<br />
Building Scribus yourself is not as hard as it sounds. In the rest of this page you'll find an answer to (almost) every question, you could have about this subject. It is worth reading, but you hopefully won't have to bother with most of the problems outlined here.<br />
<br />
So, you may be interested in just knowing how it works in the best case.<br />
<br />
Using Linux, it just boils down to:<br />
<br />
<pre><br />
mkdir ~/src/<br />
mkdir ~/src/scribus_svn<br />
sudo mkdir /usr/local/scribus_svn<br />
cd ~/src/scribus_svn<br />
svn co svn://scribus.info/Scribus/trunk/Scribus<br />
cd ./Scribus<br />
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/scribus_svn<br />
make<br />
sudo "make install"<br />
</pre><br />
<br />
* you may change ~/src/ to wherever you want to put your source into.<br />
* you may change /usr/local/scribus_svn/ to wherever you want to put the Scribus binaries.<br />
<br />
Now, if you want to understand what that commands mean, you will have to read through the rest of this page...<br />
<br />
== The easy way for Debian users ==<br />
<br />
If you're using Debian (or Ubuntu) you need to manually compile the SVN version, only if you want to be really really up to date.<br />
<br />
Otherwise, you can rely on the .deb for scribus-ng in our own repositories or, if you don't find the packages for your platform (ppc, 64 bit) you can let apt-get compile from source using the latest sources in the repositories (most of the time those will be older than the SVN ones, but you probably don't really care).<br />
<br />
You first have to add the source line for deb-src in synaptic, then you should become root (<kbd>sudo -i</kbd>) and:<br />
<br />
<pre><br />
apt-get source scribus-ng;<br />
cd scribus-ng-1.3.5.dfsg~svn20090208;<br />
apt-get build-dep scribus-ng;<br />
debuild -us -uc; dpkg -i <br />
../scribus-ng_1.3.5.dfsg~svn20090208-3_i386.deb<br />
</pre><br />
<br />
For more information on using Scribus with debian, please have a look at the [http://www.scribus.net/?q=debian Debian page our offical site]<br />
<br />
==First thing first: Download latest snapshot with Subversion==<br />
<br />
Subversion is the versioning control system used for Scribus. Check [[Subversion | this link]] for instructions for using Subversion.<br />
<br />
All subversion URLs for Scribus anonsvn are based at:<br />
<br />
'''svn://scribus.info/Scribus/'''<br />
<br />
There's also '''http://scribus.info/svn/Scribus/''' , which gets you to the same content, but '''svn://scribus.info/Scribus/''' is usually faster. HTTP access might be useful to those behind paranoid firewalls or proxies, though.<br />
<br />
If you used to check out -r <Version>, check out <SVN Path> instead:<br />
{| cellspacing="10" cellpadding="6"<br />
! Version !! !! SVN Path !! Status<br />
|-<br />
|Version150 || ||/trunk/Scribus || **really unstable/development version**<br />
|-<br />
|Version135 || ||/branches/Version135/Scribus || **unstable/development version**<br />
|-<br />
|Version133x || ||/branches/Version133x/Scribus || **stable version**<br />
|}<br />
<br />
So, if I wanted to use svn:// to check out 1.3.3.xsvn, I'd run:<br />
<br />
<tt><b>svn co svn://scribus.info/Scribus/branches/Version133x/Scribus scribus133x</b></tt><br />
<br />
Updating your working copy is much the same as cvs - just cd into your<br />
working copy and run "svn up" .<br />
<br />
<br />
Some links to learn more about downloading Scribus and about SVN:<br />
* There is an online reference for SVN at [http://svnbook.red-bean.com/nightly/en/index.html this site.]<br />
* Once you have subversion installed, you can get some help for SVN at the command line by entering <tt>svn help</tt><br />
* See the installing section on [http://docs.scribus.net docs.scribus.net] for more info on the Official Documentation site.<br />
* Craig Ringer [http://nashi.altmuehlnet.de/pipermail/scribus/2007-May/024130.html explained how to use SVN with Scribus] on the list.<br />
<br />
Thanks to Anduin.net [[http://anduin.net/]], anonymous SVN access is updated daily.<br />
<br />
'''More info on downloading scribus:'''<br />
*Standard download [http://docs.scribus.net/index.php?lang=en&page=download]<br />
*CVS download [http://docs.scribus.net/index.php?lang=en&page=install1]<br />
<br />
If you are compiling for the first time, don't be scared of the command line. Just copy the lines relevant to the version of Scribus you want to use, one by one on the command line. <br />
<br />
'''Watch out:'''<br />
*Newbies should take care, that only 'make install' part has to be done as a root. Rest of the part, like downloading and compiling can be done easily as a normal users.<br>You ''can'' install as a user, however, if you are installing into a directory you have write permission for. See the <tt>-DCMAKE_INSTALL_PREFIX</tt> command below.<br />
* And if u already have a version of Scribus on your system, don't forget to use the option WANT_VERSIONING=1. You can specify this option as -DWANT_VERSIONING=1. <br />
<br />
Good luck!<br />
===Getting All the Things You Need===<br />
This is probably something of a worst-case scenario, but likely representative for a situation for a newbie having no built-in capability to compile software. <br />
<br />
An installation of Fedora 8 was done on a computer having no DVD drive, so therefore a CD had to be used, in this case the Fedora-8-Live-KDE CD. Installing Fedora 8 in this manner is simple, since everything on the CD gets installed, but you have no capability to compile software &ndash; none whatsoever.<br />
<br />
The basic beginning packages needed are these, obtained with <code>yum install</code>... :<br />
* gcc<br />
* gcc-c++<br />
* cmake<br />
* subversion &ndash; if you're going to compile, you might as well get the latest Scribus updates<br />
<br />
So if you follow the instructions above for downloading using <code>svn</code>, then use Cmake, you have ''many'' dependencies to deal with, so get these before you even try Cmake the first time:<br />
* ghostscript &ndash; this should already be there<br />
* qt-devel<br />
* pkgconfig<br />
* lcms-devel<br />
* libjpeg-devel<br />
* libtiff-devel<br />
* libart_lgpl-devel<br />
* cups-devel<br />
* libxml2 and libxml2-devel &ndash; you should already have libxml2<br />
* python and python-devel<br />
* fontconfig-devel<br />
* openssl-devel<br />
* freetype and freetype-devel<br />
* python-imaging-devel<br />
* tk and tkinter<br />
<br />
If you're going to be more adventuresome and compile 1.3.5svn, then you will need these:<br />
* cairo and cairo-devel &ndash; you should already have cairo<br />
* qt4 and qt4-devel<br />
<br />
For Fedora at least, the names are as used with yum, for example:<br />
<br />
<code>yum install qt-devel lcms-devel libjpeg-devel libtiff-devel</code><br />
<br />
and so on. On other distros the exact names may vary. [http://www.boyden.us/scribus.html Here is a link] describing the particulars for Ubuntu 7.10 (Gutsy Gibbon):<br />
<br />
On <strong>Fedora</strong>, if you install various development packages, you have most of what you need. Exceptions seem to be cups-devel, lcms-devel, tk and tkinter, and python-imaging-devel (maybe cairo-devel). Incidentally, in Fedora 9 and later, Qt4 is loaded by default, and is labeled only qt and qt-devel.<br />
<br />
====GraphicsMagick====<br />
You do not need GraphicsMagick to run cmake or compile 1.5.0svn, but some added capabilities will be present if you have it. What Scribus needs are the following (Fedora nomenclature): GraphicsMagick, GraphicsMagick-devel, GraphicsMagick-c++, and GraphicsMagick-c++-devel. These last two are tricky, since the message from cmake will tell you that GraphicsMagick++ is missing, but this is the name of the lib file, not the package.<br />
<br />
Yum can help you with these kinds of things to avoid having to browse a repository. <br />
<br />
<tt>yum list GraphicMagick*</tt> will show a list of available packages<br />
<br />
<tt>yum install GraphicsMagick*</tt> will install all of them.<br />
<br />
==Why Do I Have to 'Build' Scribus?==<br />
'''For that matter, what is Building?'''<br />
<br />
When you are going to build or compile Scribus, what you have downloaded is a large collection of plain-text files (ending in '.c' or '.cpp' to denote either the C or C++ language respectively). The reason there are so many is that this actually makes the process of developing software easier, and allows for use of small parts repeatedly by different functions of the overall program. These plain-text files need to be converted to binary files (ending in ',o' for object files) so that your PC can use them, and the program works efficiently.<br />
<br />
The first step is to configure your downloaded directory of files. This requires a check of your PC to make sure the compiling programs and all the other required outside resources are present and sufficiently up-to-date. Just as Scribus itself consists of these small program files, it also will use those of outside programs, like CUPS, lcms, and so on, so it needs to have on hand those plain text files to connect to these outside resources. After checking for the necessary resources, a script is written to tell the compiler how to go about building Scribus. The process will fail if you are missing something, and '''cmake''' will give you error messages.<br />
<br />
The Scribus Team now encourages the use of '''cmake''' for this configuring process. It is quick, easy to use, and easy for the developers to write for -- even '''cmake''' needs instructions. You can also pass to '''cmake''' several special parameters for your particular PC setup, where you want Scribus to be installed, for example.<br />
<br />
Next, the actual 'build' process is done with a program called '''make'''. To start the process you simply enter <tt>make</tt> in a command line. That's it. You do not need to have ''root'' privileges to compile, and it is generally recommended that do not compile as root (one reason for this is that, by creating a number of files under root's name, you then interfere with subsequent updating from SVN). Compiling takes up a good part of your computer's resources, especially your processor(s), so you will find its performance rather sluggish while compiling is going on. Consequently, many find that compiling is best done by starting '''make''' and then walking away from the PC to let it do its work.<br />
<br />
Finally, you need to install, done with the command <tt>make install</tt>. If you are going to install in the default location, you will need to have ''root'' privileges. On most Linux distros this can easily be done with the <tt>su</tt> command (after which you need root's password), or with '''sudo''', entered as <tt>sudo make install</tt>. You can run '''cmake''' with a command that can install Scribus in a directory for which you have write privileges, and therefore do not need to be '' root''. <br />
<br />
For this help, and other advice, continue reading the following sections.<br />
<br />
==To start the build==<br />
Before continuing, please note that an out-of-source build is recommended, however..<br />
From the Scribus directory:<br />
<br />
<code>/path/to/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/path/to/install/to/scribuscmake/</code><br />
<br />
For example:<br />
<br />
<code>/usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus134cvs</code><br />
<br />
Some options that the Scribus CMake files know about (more to come!):<br />
*WANT_VERSIONING=1: Sets the build to use the VERSION setting as a suffix for the install directories and the binary. Eg, the binary could be <code>scribus-1.3.5svn</code>. This should mean that you can install multiple versions with the same prefix with no clashes.<br />
*WANT_DEBUG=1: Sets the build to be a debug release and use -O0 -g3, instead of -O2 (This is the default for now, and cannot be turned off unless you edit the CMakeFiles.txt file).<br />
*WANT_CAIRO=1: Makes CMake search for cairo and build with cairo instead of LibArt_LGPL. cairo is the primary supported option for 1.3.5+.<br />
*WANT_LIBART=1 (not available in 1.3.5, default in 1.3.3.x): Makes CMake search for and build with LibArt_LGPL instead of cairo.<br />
*WANT_QTARTHUR=1: In 1.3.5, uses the QT4 ARTHUR rendering library. This is an alternative to CAIRO.<br />
<br />
If you have several version of QT installed or QT is installed in a non standard location you'll have to tell cmake where to find it by setting <code>-DQT_QMAKE_EXECUTABLE</code><br />
<br />
For example: to make a cairo debug build, then something like this:<br />
<br />
<code>/usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus134cvs -DWANT_CAIRO=1 -DWANT_DEBUG=1 -DWANT_VERSIONING=1</code><br />
<br />
To use qt_arthur instead:<br />
<br />
<code>/usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus134cvs -DWANT_QTARTHUR=1 -DWANT_DEBUG=1 -DWANT_VERSIONING=1</code><br />
<br />
==Out-of-source builds==<br />
One of the advantages of CMake is that you can do an out-of-source build. What is this? It enables you to build the application without writing anything at all to the directory where the Scribus source is. This means your source tree is clean, always. Its easier and faster to update, and you can build multiple targets out-of-source from the same source tree. Cool!<br />
<br />
To do an out-of-source build, you need a new directory to build in. <br />
Say you have the source files in:<br />
<br />
<code>/home/username/scribuscmake/Scribus</code><br />
<br />
Make the following directory:<br />
<br />
<code>/home/username/scribuscmake/builddir</code><br />
<br />
So then, instead of doing:<br />
<br />
<code>eg /usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus134cvs</code><br />
<br />
you would then change to the builddir directory and run:<br />
<br />
<code>eg /usr/local/bin/cmake ../Scribus -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus134cvs</code><br />
<br />
Simple!<br />
<br />
==Continuing on to the build stage==<br />
<br />
Once this has successfully completed, simply run <code>make && make install</code>.<br />
<br />
The CMake based build system is very new to Scribus and it will change and it will need improving. Please report issues on our mailing list or bugtracker.<br />
<br />
There is a long todo list for this build system including, but not limited to:<br />
*Checking it works across distributions<br />
*Checking it works across various flavours of UNIX<br />
*Checking it works on 64 bit distros<br />
*Add Win32 and Mac OSX support<br />
<br />
==Compilation fails using Qt4 binaries==<br />
<br />
Systems with both Qt3 and Qt4 installed: You have <code>uic</code> and <code>moc</code> from Qt4 in the path and it ''may'' results to the compilation crash. This should ''NOT'' be the case with cmake 2.4.2 when released, or when using current Scribus CVS. However, this might be a useful workaround:<br />
<br />
Remove cached options from previous cmake configuration run:<br />
<code>rm CMakeCache.txt</code><br />
<br />
Then change PATH variable (for my Gentoo) e.g.:<br />
<code>export PATH=/usr/qt/3/bin/:$PATH</code><br />
<br />
And run cmake config phase again:<br />
<br />
eg <code>~/devel/CMAKE/bin/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/path/to/install/to/scribuscmake/ </code><br />
<br />
==Specific library locations==<br />
Whenever your distribution releases their package for a library Scribus depends on, it may still not be the very latest stable or unstable version from the writers of the library. In some cases, the Scribus developers have had to rely on the very latest code to further some parts of Scribus. In this case it is necessary to build your own version of such a library.<br />
<br />
On example of this is the [http://cairographics.org cairo graphics library]. Right now, 1.3.5svn has the capability to use the very very latest code from the just released cairo 1.4.<br />
<br />
To specify a new cairo install path, other than your system's default add this to the cmake command line:<br />
<code>-DPREFIX_CAIRO:PATH=/path/to/your/cairo/install</code><br />
<br />
==Instructions for specific distributions or versions==<br />
<br />
*[[http://boyden.us/scribus.html Scribus 1.3.5svn for Ubuntu 7.10 "Gutsy Gibbon"]]<br />
<br />
<br />
==Making a tarball for distribution==<br />
<br />
To make a tarball for distribution, the old way would be to <code>make dist</code>. The new way is to run <code>make package_source</code> or <code>/path/to/cpack -G TBZ2 --config CPackSourceConfig.cmake</code> to give you a bundle of the source. With cmake 2.4.1 there is only support for a gzip <code>tar.gz</code> however a bzip2 <code>tar.bz2</code> is possible with later versions of cmake.<br />
<br />
=== Notes For Packagers ===<br />
If you package Scribus for a distribution keep in mind the issue of the install prefix versus temporary install directory prefix. The following seems to work well for Debian packaging:<br />
<br />
<code><br />
>_______mkdir -p $(BUILD_DIR)<br />
>_______cd $(BUILD_DIR) && $(CMAKE) \<br />
>_______ -DWANT_DEBUG:STRING=$(DEBUG_FLAG) \<br />
>_______ -DCMAKE_INSTALL_PREFIX:PATH=/usr \<br />
>_______ -DCMAKE_SKIP_RPATH:BOOL=1 \<br />
>_______ -DRPATH_STYLE:STRING=none \<br />
>_______ -DWANT_VERSIONING:BOOL=1 \<br />
>_______ -DCUSTOM_VERSIONTAG:STRING=-ng \<br />
>_______ -DCMAKE_CXX_FLAGS:STRING='-o2 -g -Wall' \<br />
>_______ -DCMAKE_C_FLAGS:STRING='-o2 -g -Wall' ../../<br />
</code><br />
<br />
then<br />
<br />
<code><br />
>_______$(MAKE) -C $(BUILD_DIR) install DESTDIR=$(INSTALL_DIR)<br />
</code><br />
<br />
where $(BUILD_DIR) is ./build and $(INSTALL_DIR) is ./install<br />
<br />
Using $(PREFIX) is the key to avoiding hardcoded absolute path problem.<br />
<br />
==TODO==<br />
*Enable more pkg-config usage<br />
*64 bit supoprt<br />
*Prefixes for more packages<br />
<br />
==Success Stories==<br />
<br />
Please add the operating system or distribution that you have tested successfully on:<br />
*Gentoo, current (--[[User:Cbradney|Cbradney]] 17:04, 12 November 2006 (CET))<br />
<br />
*Kubuntu Dapper Drake (--[[User:TomZ|TomZ]] 17:08, 12 November 2006 (CET))<br />
*Ubuntu Feisty (--[[User:Oberten|Oberten]] 23 March 2007)<br />
*Ubuntu Gutsy 32bits (--[[User:Brunod|Brunod]] 24 November 2007)<br />
*Ubuntu Hardy (--[[User:a.l.e|a.l.e]] 30 May 2008)<br />
<br />
*SuSE Linux 10.0 (--[[User:C_Schaefer|C_schaefer]] 19 November 2006)<br />
*openSuse 10.1 (--[[User:TomZ|TomZ]] 17:08, 12 November 2006 (CET))<br />
*OpenSuSE 10.2 (--[[User:C_Schaefer|C_schaefer]] 28 February 2007)<br />
*OpenSUSE 10.3<br />
*SUSE Linux Enterprise Desktop 10 (i586) --[[User:Mhanski|Mhanski]] 15:41, 21 April 2007 (CEST)<br />
<br />
*Fedora Core 6 (--[[User:gpittman|gpittman]] 15:44, 12 November 2006 (EST))<br />
*Fedora 8 i386 (--[[User:Zoonfafer|Zoonfafer]] 12:42, 10 December 2007 (CET))<br />
*Fedora 9 (--[[User:Gpittman|G Pittman]])<br />
*Fedora 12 (--[[User:Hhartley|Hhartley]] 02:32, 12 May 2010 (CEST))<br />
*Fedora 13 (--[[User:Hhartley|Hhartley]] 00:27, 29 May 2010 (CEST))<br />
<br />
*PLD Linux Th (--[[User:Deejay1|DeeJay1]] 09:52, 13 November 2006 (CET))<br />
<br />
*Mandriva 2007 (--[[User:Leo|Leo]] [[mailto:leo.thealmighty@gmail.com]] 01:00, 16 November, 2006 (IST)) - a smooth ride<br />
<br />
*PCLinuxOS 0.93a (--[[User:Leo|Leo]] [[mailto:leo.thealmighty@gmail.com]] few days before i tried mandriva 2007) - manualy specified lib locations<br />
<br />
* MacOSX 10.4 Tiger (--[[User:Avox|avox]] 18:50, 1 March 2007 (CET)) check the advanced settings with ccmake, sometimes it doesnt pick up some paths<br />
<br />
*Debian Sid and Lenny (--[[User:Gemy_c|Gemy_c]] 06 August 2007 and for a long time ;) )</div>Hhartleyhttps://wiki.scribus.net/wiki/index.php?title=Building_SVN_versions_with_CMake&diff=22029Building SVN versions with CMake2010-05-12T00:32:59Z<p>Hhartley: /* Success Stories */ Add CentOS 5</p>
<hr />
<div>[[Category:Scribus_development]]<br />
<br />
After many years of using the autotools build system, the developers of Scribus have selected [http://www.cmake.org CMake] as a replacement system. It provides a much more flexible setup with a lot less complexity. It also provides compatibility with build tools on Linux and variants of Unix, Windows and Mac OSX.<br />
<br />
'''You must have CMake version &ge; 2.4.3 for best results. Older versions will fail.'''<br />
<br />
==Introduction: don't let it scare you off==<br />
<br />
Building Scribus yourself is not as hard as it sounds. In the rest of this page you'll find an answer to (almost) every question, you could have about this subject. It is worth reading, but you hopefully won't have to bother with most of the problems outlined here.<br />
<br />
So, you may be interested in just knowing how it works in the best case.<br />
<br />
Using Linux, it just boils down to:<br />
<br />
<pre><br />
mkdir ~/src/<br />
mkdir ~/src/scribus_svn<br />
sudo mkdir /usr/local/scribus_svn<br />
cd ~/src/scribus_svn<br />
svn co svn://scribus.info/Scribus/trunk/Scribus<br />
cd ./Scribus<br />
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/scribus_svn<br />
make<br />
sudo "make install"<br />
</pre><br />
<br />
* you may change ~/src/ to wherever you want to put your source into.<br />
* you may change /usr/local/scribus_svn/ to wherever you want to put the Scribus binaries.<br />
<br />
Now, if you want to understand what that commands mean, you will have to read through the rest of this page...<br />
<br />
== The easy way for Debian users ==<br />
<br />
If you're using Debian (or Ubuntu) you need to manually compile the SVN version, only if you want to be really really up to date.<br />
<br />
Otherwise, you can rely on the .deb for scribus-ng in our own repositories or, if you don't find the packages for your platform (ppc, 64 bit) you can let apt-get compile from source using the latest sources in the repositories (most of the time those will be older than the SVN ones, but you probably don't really care).<br />
<br />
You first have to add the source line for deb-src in synaptic, then you should become root (<kbd>sudo -i</kbd>) and:<br />
<br />
<pre><br />
apt-get source scribus-ng;<br />
cd scribus-ng-1.3.5.dfsg~svn20090208;<br />
apt-get build-dep scribus-ng;<br />
debuild -us -uc; dpkg -i <br />
../scribus-ng_1.3.5.dfsg~svn20090208-3_i386.deb<br />
</pre><br />
<br />
For more information on using Scribus with debian, please have a look at the [http://www.scribus.net/?q=debian Debian page our offical site]<br />
<br />
==First thing first: Download latest snapshot with Subversion==<br />
<br />
Subversion is the versioning control system used for Scribus. Check [[Subversion | this link]] for instructions for using Subversion.<br />
<br />
All subversion URLs for Scribus anonsvn are based at:<br />
<br />
'''svn://scribus.info/Scribus/'''<br />
<br />
There's also '''http://scribus.info/svn/Scribus/''' , which gets you to the same content, but '''svn://scribus.info/Scribus/''' is usually faster. HTTP access might be useful to those behind paranoid firewalls or proxies, though.<br />
<br />
If you used to check out -r <Version>, check out <SVN Path> instead:<br />
{| cellspacing="10" cellpadding="6"<br />
! Version !! !! SVN Path !! Status<br />
|-<br />
|Version150 || ||/trunk/Scribus || **really unstable/development version**<br />
|-<br />
|Version135 || ||/branches/Version135/Scribus || **unstable/development version**<br />
|-<br />
|Version133x || ||/branches/Version133x/Scribus || **stable version**<br />
|}<br />
<br />
So, if I wanted to use svn:// to check out 1.3.3.xsvn, I'd run:<br />
<br />
<tt><b>svn co svn://scribus.info/Scribus/branches/Version133x/Scribus scribus133x</b></tt><br />
<br />
Updating your working copy is much the same as cvs - just cd into your<br />
working copy and run "svn up" .<br />
<br />
<br />
Some links to learn more about downloading Scribus and about SVN:<br />
* There is an online reference for SVN at [http://svnbook.red-bean.com/nightly/en/index.html this site.]<br />
* Once you have subversion installed, you can get some help for SVN at the command line by entering <tt>svn help</tt><br />
* See the installing section on [http://docs.scribus.net docs.scribus.net] for more info on the Official Documentation site.<br />
* Craig Ringer [http://nashi.altmuehlnet.de/pipermail/scribus/2007-May/024130.html explained how to use SVN with Scribus] on the list.<br />
<br />
Thanks to Anduin.net [[http://anduin.net/]], anonymous SVN access is updated daily.<br />
<br />
'''More info on downloading scribus:'''<br />
*Standard download [http://docs.scribus.net/index.php?lang=en&page=download]<br />
*CVS download [http://docs.scribus.net/index.php?lang=en&page=install1]<br />
<br />
If you are compiling for the first time, don't be scared of the command line. Just copy the lines relevant to the version of Scribus you want to use, one by one on the command line. <br />
<br />
'''Watch out:'''<br />
*Newbies should take care, that only 'make install' part has to be done as a root. Rest of the part, like downloading and compiling can be done easily as a normal users.<br>You ''can'' install as a user, however, if you are installing into a directory you have write permission for. See the <tt>-DCMAKE_INSTALL_PREFIX</tt> command below.<br />
* And if u already have a version of Scribus on your system, don't forget to use the option WANT_VERSIONING=1. You can specify this option as -DWANT_VERSIONING=1. <br />
<br />
Good luck!<br />
===Getting All the Things You Need===<br />
This is probably something of a worst-case scenario, but likely representative for a situation for a newbie having no built-in capability to compile software. <br />
<br />
An installation of Fedora 8 was done on a computer having no DVD drive, so therefore a CD had to be used, in this case the Fedora-8-Live-KDE CD. Installing Fedora 8 in this manner is simple, since everything on the CD gets installed, but you have no capability to compile software &ndash; none whatsoever.<br />
<br />
The basic beginning packages needed are these, obtained with <code>yum install</code>... :<br />
* gcc<br />
* gcc-c++<br />
* cmake<br />
* subversion &ndash; if you're going to compile, you might as well get the latest Scribus updates<br />
<br />
So if you follow the instructions above for downloading using <code>svn</code>, then use Cmake, you have ''many'' dependencies to deal with, so get these before you even try Cmake the first time:<br />
* ghostscript &ndash; this should already be there<br />
* qt-devel<br />
* pkgconfig<br />
* lcms-devel<br />
* libjpeg-devel<br />
* libtiff-devel<br />
* libart_lgpl-devel<br />
* cups-devel<br />
* libxml2 and libxml2-devel &ndash; you should already have libxml2<br />
* python and python-devel<br />
* fontconfig-devel<br />
* openssl-devel<br />
* freetype and freetype-devel<br />
* python-imaging-devel<br />
* tk and tkinter<br />
<br />
If you're going to be more adventuresome and compile 1.3.5svn, then you will need these:<br />
* cairo and cairo-devel &ndash; you should already have cairo<br />
* qt4 and qt4-devel<br />
<br />
For Fedora at least, the names are as used with yum, for example:<br />
<br />
<code>yum install qt-devel lcms-devel libjpeg-devel libtiff-devel</code><br />
<br />
and so on. On other distros the exact names may vary. [http://www.boyden.us/scribus.html Here is a link] describing the particulars for Ubuntu 7.10 (Gutsy Gibbon):<br />
<br />
On <strong>Fedora</strong>, if you install various development packages, you have most of what you need. Exceptions seem to be cups-devel, lcms-devel, tk and tkinter, and python-imaging-devel (maybe cairo-devel). Incidentally, in Fedora 9 and later, Qt4 is loaded by default, and is labeled only qt and qt-devel.<br />
<br />
====GraphicsMagick====<br />
You do not need GraphicsMagick to run cmake or compile 1.5.0svn, but some added capabilities will be present if you have it. What Scribus needs are the following (Fedora nomenclature): GraphicsMagick, GraphicsMagick-devel, GraphicsMagick-c++, and GraphicsMagick-c++-devel. These last two are tricky, since the message from cmake will tell you that GraphicsMagick++ is missing, but this is the name of the lib file, not the package.<br />
<br />
Yum can help you with these kinds of things to avoid having to browse a repository. <br />
<br />
<tt>yum list GraphicMagick*</tt> will show a list of available packages<br />
<br />
<tt>yum install GraphicsMagick*</tt> will install all of them.<br />
<br />
==Why Do I Have to 'Build' Scribus?==<br />
'''For that matter, what is Building?'''<br />
<br />
When you are going to build or compile Scribus, what you have downloaded is a large collection of plain-text files (ending in '.c' or '.cpp' to denote either the C or C++ language respectively). The reason there are so many is that this actually makes the process of developing software easier, and allows for use of small parts repeatedly by different functions of the overall program. These plain-text files need to be converted to binary files (ending in ',o' for object files) so that your PC can use them, and the program works efficiently.<br />
<br />
The first step is to configure your downloaded directory of files. This requires a check of your PC to make sure the compiling programs and all the other required outside resources are present and sufficiently up-to-date. Just as Scribus itself consists of these small program files, it also will use those of outside programs, like CUPS, lcms, and so on, so it needs to have on hand those plain text files to connect to these outside resources. After checking for the necessary resources, a script is written to tell the compiler how to go about building Scribus. The process will fail if you are missing something, and '''cmake''' will give you error messages.<br />
<br />
The Scribus Team now encourages the use of '''cmake''' for this configuring process. It is quick, easy to use, and easy for the developers to write for -- even '''cmake''' needs instructions. You can also pass to '''cmake''' several special parameters for your particular PC setup, where you want Scribus to be installed, for example.<br />
<br />
Next, the actual 'build' process is done with a program called '''make'''. To start the process you simply enter <tt>make</tt> in a command line. That's it. You do not need to have ''root'' privileges to compile, and it is generally recommended that do not compile as root (one reason for this is that, by creating a number of files under root's name, you then interfere with subsequent updating from SVN). Compiling takes up a good part of your computer's resources, especially your processor(s), so you will find its performance rather sluggish while compiling is going on. Consequently, many find that compiling is best done by starting '''make''' and then walking away from the PC to let it do its work.<br />
<br />
Finally, you need to install, done with the command <tt>make install</tt>. If you are going to install in the default location, you will need to have ''root'' privileges. On most Linux distros this can easily be done with the <tt>su</tt> command (after which you need root's password), or with '''sudo''', entered as <tt>sudo make install</tt>. You can run '''cmake''' with a command that can install Scribus in a directory for which you have write privileges, and therefore do not need to be '' root''. <br />
<br />
For this help, and other advice, continue reading the following sections.<br />
<br />
==To start the build==<br />
Before continuing, please note that an out-of-source build is recommended, however..<br />
From the Scribus directory:<br />
<br />
<code>/path/to/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/path/to/install/to/scribuscmake/</code><br />
<br />
For example:<br />
<br />
<code>/usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus134cvs</code><br />
<br />
Some options that the Scribus CMake files know about (more to come!):<br />
*WANT_VERSIONING=1: Sets the build to use the VERSION setting as a suffix for the install directories and the binary. Eg, the binary could be <code>scribus-1.3.5svn</code>. This should mean that you can install multiple versions with the same prefix with no clashes.<br />
*WANT_DEBUG=1: Sets the build to be a debug release and use -O0 -g3, instead of -O2 (This is the default for now, and cannot be turned off unless you edit the CMakeFiles.txt file).<br />
*WANT_CAIRO=1: Makes CMake search for cairo and build with cairo instead of LibArt_LGPL. cairo is the primary supported option for 1.3.5+.<br />
*WANT_LIBART=1 (not available in 1.3.5, default in 1.3.3.x): Makes CMake search for and build with LibArt_LGPL instead of cairo.<br />
*WANT_QTARTHUR=1: In 1.3.5, uses the QT4 ARTHUR rendering library. This is an alternative to CAIRO.<br />
<br />
If you have several version of QT installed or QT is installed in a non standard location you'll have to tell cmake where to find it by setting <code>-DQT_QMAKE_EXECUTABLE</code><br />
<br />
For example: to make a cairo debug build, then something like this:<br />
<br />
<code>/usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus134cvs -DWANT_CAIRO=1 -DWANT_DEBUG=1 -DWANT_VERSIONING=1</code><br />
<br />
To use qt_arthur instead:<br />
<br />
<code>/usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus134cvs -DWANT_QTARTHUR=1 -DWANT_DEBUG=1 -DWANT_VERSIONING=1</code><br />
<br />
==Out-of-source builds==<br />
One of the advantages of CMake is that you can do an out-of-source build. What is this? It enables you to build the application without writing anything at all to the directory where the Scribus source is. This means your source tree is clean, always. Its easier and faster to update, and you can build multiple targets out-of-source from the same source tree. Cool!<br />
<br />
To do an out-of-source build, you need a new directory to build in. <br />
Say you have the source files in:<br />
<br />
<code>/home/username/scribuscmake/Scribus</code><br />
<br />
Make the following directory:<br />
<br />
<code>/home/username/scribuscmake/builddir</code><br />
<br />
So then, instead of doing:<br />
<br />
<code>eg /usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus134cvs</code><br />
<br />
you would then change to the builddir directory and run:<br />
<br />
<code>eg /usr/local/bin/cmake ../Scribus -DCMAKE_INSTALL_PREFIX:PATH=/opt/scribus134cvs</code><br />
<br />
Simple!<br />
<br />
==Continuing on to the build stage==<br />
<br />
Once this has successfully completed, simply run <code>make && make install</code>.<br />
<br />
The CMake based build system is very new to Scribus and it will change and it will need improving. Please report issues on our mailing list or bugtracker.<br />
<br />
There is a long todo list for this build system including, but not limited to:<br />
*Checking it works across distributions<br />
*Checking it works across various flavours of UNIX<br />
*Checking it works on 64 bit distros<br />
*Add Win32 and Mac OSX support<br />
<br />
==Compilation fails using Qt4 binaries==<br />
<br />
Systems with both Qt3 and Qt4 installed: You have <code>uic</code> and <code>moc</code> from Qt4 in the path and it ''may'' results to the compilation crash. This should ''NOT'' be the case with cmake 2.4.2 when released, or when using current Scribus CVS. However, this might be a useful workaround:<br />
<br />
Remove cached options from previous cmake configuration run:<br />
<code>rm CMakeCache.txt</code><br />
<br />
Then change PATH variable (for my Gentoo) e.g.:<br />
<code>export PATH=/usr/qt/3/bin/:$PATH</code><br />
<br />
And run cmake config phase again:<br />
<br />
eg <code>~/devel/CMAKE/bin/cmake . -DCMAKE_INSTALL_PREFIX:PATH=/path/to/install/to/scribuscmake/ </code><br />
<br />
==Specific library locations==<br />
Whenever your distribution releases their package for a library Scribus depends on, it may still not be the very latest stable or unstable version from the writers of the library. In some cases, the Scribus developers have had to rely on the very latest code to further some parts of Scribus. In this case it is necessary to build your own version of such a library.<br />
<br />
On example of this is the [http://cairographics.org cairo graphics library]. Right now, 1.3.5svn has the capability to use the very very latest code from the just released cairo 1.4.<br />
<br />
To specify a new cairo install path, other than your system's default add this to the cmake command line:<br />
<code>-DPREFIX_CAIRO:PATH=/path/to/your/cairo/install</code><br />
<br />
==Instructions for specific distributions or versions==<br />
<br />
*[[http://boyden.us/scribus.html Scribus 1.3.5svn for Ubuntu 7.10 "Gutsy Gibbon"]]<br />
<br />
<br />
==Making a tarball for distribution==<br />
<br />
To make a tarball for distribution, the old way would be to <code>make dist</code>. The new way is to run <code>make package_source</code> or <code>/path/to/cpack -G TBZ2 --config CPackSourceConfig.cmake</code> to give you a bundle of the source. With cmake 2.4.1 there is only support for a gzip <code>tar.gz</code> however a bzip2 <code>tar.bz2</code> is possible with later versions of cmake.<br />
<br />
=== Notes For Packagers ===<br />
If you package Scribus for a distribution keep in mind the issue of the install prefix versus temporary install directory prefix. The following seems to work well for Debian packaging:<br />
<br />
<code><br />
>_______mkdir -p $(BUILD_DIR)<br />
>_______cd $(BUILD_DIR) && $(CMAKE) \<br />
>_______ -DWANT_DEBUG:STRING=$(DEBUG_FLAG) \<br />
>_______ -DCMAKE_INSTALL_PREFIX:PATH=/usr \<br />
>_______ -DCMAKE_SKIP_RPATH:BOOL=1 \<br />
>_______ -DRPATH_STYLE:STRING=none \<br />
>_______ -DWANT_VERSIONING:BOOL=1 \<br />
>_______ -DCUSTOM_VERSIONTAG:STRING=-ng \<br />
>_______ -DCMAKE_CXX_FLAGS:STRING='-o2 -g -Wall' \<br />
>_______ -DCMAKE_C_FLAGS:STRING='-o2 -g -Wall' ../../<br />
</code><br />
<br />
then<br />
<br />
<code><br />
>_______$(MAKE) -C $(BUILD_DIR) install DESTDIR=$(INSTALL_DIR)<br />
</code><br />
<br />
where $(BUILD_DIR) is ./build and $(INSTALL_DIR) is ./install<br />
<br />
Using $(PREFIX) is the key to avoiding hardcoded absolute path problem.<br />
<br />
==TODO==<br />
*Enable more pkg-config usage<br />
*64 bit supoprt<br />
*Prefixes for more packages<br />
<br />
==Success Stories==<br />
<br />
Please add the operating system or distribution that you have tested successfully on:<br />
*Gentoo, current (--[[User:Cbradney|Cbradney]] 17:04, 12 November 2006 (CET))<br />
<br />
*Kubuntu Dapper Drake (--[[User:TomZ|TomZ]] 17:08, 12 November 2006 (CET))<br />
*Ubuntu Feisty (--[[User:Oberten|Oberten]] 23 March 2007)<br />
*Ubuntu Gutsy 32bits (--[[User:Brunod|Brunod]] 24 November 2007)<br />
*Ubuntu Hardy (--[[User:a.l.e|a.l.e]] 30 May 2008)<br />
<br />
*SuSE Linux 10.0 (--[[User:C_Schaefer|C_schaefer]] 19 November 2006)<br />
*openSuse 10.1 (--[[User:TomZ|TomZ]] 17:08, 12 November 2006 (CET))<br />
*OpenSuSE 10.2 (--[[User:C_Schaefer|C_schaefer]] 28 February 2007)<br />
*OpenSUSE 10.3<br />
*SUSE Linux Enterprise Desktop 10 (i586) --[[User:Mhanski|Mhanski]] 15:41, 21 April 2007 (CEST)<br />
<br />
*Fedora Core 6 (--[[User:gpittman|gpittman]] 15:44, 12 November 2006 (EST))<br />
*Fedora 8 i386 (--[[User:Zoonfafer|Zoonfafer]] 12:42, 10 December 2007 (CET))<br />
*Fedora 9 (--[[User:Gpittman|G Pittman]])<br />
<br />
*CentOS 5 (--[[User:Hhartley|Hhartley]] 02:32, 12 May 2010 (CEST))<br />
<br />
*PLD Linux Th (--[[User:Deejay1|DeeJay1]] 09:52, 13 November 2006 (CET))<br />
<br />
*Mandriva 2007 (--[[User:Leo|Leo]] [[mailto:leo.thealmighty@gmail.com]] 01:00, 16 November, 2006 (IST)) - a smooth ride<br />
<br />
*PCLinuxOS 0.93a (--[[User:Leo|Leo]] [[mailto:leo.thealmighty@gmail.com]] few days before i tried mandriva 2007) - manualy specified lib locations<br />
<br />
* MacOSX 10.4 Tiger (--[[User:Avox|avox]] 18:50, 1 March 2007 (CET)) check the advanced settings with ccmake, sometimes it doesnt pick up some paths<br />
<br />
*Debian Sid and Lenny (--[[User:Gemy_c|Gemy_c]] 06 August 2007 and for a long time ;) )</div>Hhartleyhttps://wiki.scribus.net/wiki/index.php?title=Booklettibus&diff=21551Booklettibus2009-12-09T14:29:03Z<p>Hhartley: Fixed a few typos</p>
<hr />
<div>Booklettibus is a command-line script written in php (I use PHP for scripting... it's very powerful).<br />
<br />
booklettibus.php takes a Scribus A4 document and does booklet imposition on A3 pages.<br />
<br />
*Linux: '''<tt>php booklettibus.php <input file> [<output file>]</tt>'''<br />
*Windows: '''<tt><path to php>\php.exe booklettibus.php <input file> [<output file>]</tt>'''<br />
<br />
The input file needs to be a file of Scribus >= 1.3.5 and not compressed (no sla.gz).<br />
<br />
The script works only if the document's number of pages is a multiple of 4, the layout is double-sided, and the media size is A4.<br />
<br />
It take all A4 pages and does imposition as an A3 booklet.<br />
<br />
It could be easily improved to support all media size.<br />
<br />
It works fine using my .sla document (all with the same structure automatically generated by script) but I don't know what happens using other files....<br />
<br />
After conversion the file needs to be opened using Scribus and saved so Scribus automatically fixes page attributes. Currently the script sets wrong PAGEXPOS and PAGEYPOS attributes for all "PAGE" tags but Scribus fixes them.<br />
<br />
If a document contains an object placed across two pages, it won't be correctly placed after imposition.<br />
<br />
I will be very happy, if someone wants to test the script, send me feedback or help me to improve it (You can use wiki discussion feature).<br />
<br />
Download here: [http://wiki.scribus.net/images/3/31/Booklettibus.tar.gz http://wiki.scribus.net/images/3/31/Booklettibus.tar.gz]<br />
<br />
Bye</div>Hhartleyhttps://wiki.scribus.net/wiki/index.php?title=Automatic_import_of_images:_Versions_not_requiring_Tkinter&diff=21278Automatic import of images: Versions not requiring Tkinter2009-10-01T20:12:13Z<p>Hhartley: /* album_letter_2.py */ Remove two lines</p>
<hr />
<div>{{Scripting Index}}<br />
<br />
==scribalbum_letter.py==<br />
<br />
Link to: [[Automatic import of images from a directory using a script]]<br />
<br />
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.<br />
<br />
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.<br />
<br />
Some rewriting was done so that this works with Scribus version 1.3.5svn, and the default font was changed to DejaVu Sans &ndash; if you want to use a different one, look for the <tt>labelFont</tt> variable assignment. This version of scribalbum_letter also works with Scribus 1.3.3.x.<br />
<br />
<pre><br />
#!/usr/bin/env python<br />
<br />
"""<br />
This is scribalbum_letter.py. This script will load the images from a<br />
directory, creating a new document of US Letter size.<br />
<br />
USAGE: It is probably better not to already have any document in Scribus,<br />
since memory usage can become intense when a large number of images is<br />
used. <br />
You are first presented with a dialog to choose either 4 or 6 images per page.<br />
Next select a directory where your images are located. Finally, select the <br />
types of image files, using the code you see in the last dialog. <br />
NOTE: If you choose PDF, only the first page will be imported, and the PDF <br />
will be rasterized.<br />
<br />
AUTHOR: Gregory Pittman Original version: 2005.02.13, this version: 2008.07.23<br />
<br />
LICENSE: This program is free software; you can redistribute it and/or modify <br />
it under the terms of the GNU General Public License as published by the Free <br />
Software Foundation; either version 2 of the License, or (at your option) any <br />
later version.<br />
<br />
"""<br />
<br />
import scribus<br />
import os<br />
<br />
filetype = []<br />
dicttype = {'j':'.jpg','p':'.png','t':'.tif','g':'.gif','P':'.pdf'}<br />
Dicttype = {'j':'.JPG','p':'.PNG','t':'.TIF','g':'.GIF','P':'.PDF'}<br />
nrimages = '0'<br />
while (nrimages != '4') and (nrimages != '6'):<br />
nrimages = scribus.valueDialog('Pictures','- US Letter Paper -\n Four or Six Images per Page?\nChange to 6 as desired','4')<br />
imagedir = scribus.fileDialog('Select Image Directory','Directories',isdir=True)<br />
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')<br />
for t in imagetype[0:]:<br />
filetype.append(dicttype[t])<br />
filetype.append(Dicttype[t])<br />
d = os.listdir(imagedir)<br />
D = []<br />
for file in d:<br />
for format in filetype:<br />
if file.endswith(format):<br />
D.append(file)<br />
D.sort()<br />
labelFont="DejaVu Sans Book"<br />
<br />
# When 4 pics per page, coords are: (15, 42),(310, 187), (15, 388), (310, 533)<br />
# When 6 pics per page: (15, 42),(310, 42), (15, 290), (310, 290),(15,533),(310,533)<br />
if nrimages == '4':<br />
xpos = [15, 310, 15, 310] <br />
ypos = [42, 187, 388, 533]<br />
if nrimages == '6':<br />
xpos = [15, 310, 15, 310, 15, 310]<br />
ypos = [42, 42, 290, 290, 533, 533]<br />
# This proportion is right for photographs from my digital camera<br />
pwidth = 288<br />
pheight = 193<br />
imagecount = 0<br />
#framecount = 0<br />
if len(D) > 0:<br />
if scribus.newDoc(scribus.PAPER_LETTER, (10,10,20,20),scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.NOFACINGPAGES, scribus.FIRSTPAGERIGHT):<br />
while imagecount < len(D):<br />
if imagecount > 0:<br />
scribus.newPage(-1)<br />
framecount = 0<br />
# L is the frame at the top of each page showing the directory name<br />
L = scribus.createText(15, 20, 200, 20)<br />
scribus.setText("Dir: " + imagedir, L)<br />
scribus.setTextAlignment(scribus.ALIGN_LEFT, L)<br />
scribus.setFont(labelFont, L)<br />
scribus.setFontSize(10, L)<br />
# Here is where we're loading images into the page, four at a time, then go back up for a newPage<br />
for x,y in zip(xpos,ypos):<br />
if imagecount < len(D):<br />
f = scribus.createImage(x, y, pwidth, pheight)<br />
scribus.loadImage(imagedir + '/' + D[imagecount], f)<br />
scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=f)<br />
lenfilename = len(D[imagecount])<br />
Lpiclen = int(5.3 * lenfilename)<br />
# Lpic is the label for each picture, with position and length adjusted<br />
# according to the text length, so if you change the font or its size,<br />
# you may need to adjust this only approximate calculation.<br />
Lpic = scribus.createText(x, y + 193, Lpiclen, 15)<br />
scribus.setText(D[imagecount], Lpic)<br />
scribus.setTextAlignment(scribus.ALIGN_RIGHT, Lpic)<br />
scribus.setFont(labelFont, Lpic)<br />
scribus.setFontSize(8, Lpic)<br />
scribus.setFillColor("White", Lpic)<br />
imagecount += 1<br />
<br />
scribus.setRedraw(1)<br />
scribus.redrawAll()<br />
<br />
else:<br />
result = scribus.messageBox ('Not Found','No Images found with\n this search selection',scribus.BUTTON_OK)<br />
</pre><br />
<br />
==scribalbum_a4.py==<br />
<br />
This is the version that puts 8 images on A4 paper, with little extra space. Usage is as above.<br />
<br />
<pre><br />
<nowiki><br />
#!/usr/bin/env python<br />
<br />
# File: scribalbum_a4.py<br />
# originally 2005.02.13 Gregory Pittman<br />
# this version 2006.03.17 does without Tkinter<br />
# Uses valueDialog() for data entry of directory name<br />
# and also mnemonics for image types, j=jpg, and so on.<br />
# Also searches for uppercase equivalents.<br />
# Makes a new document<br />
<br />
from scribus import *<br />
import os<br />
<br />
filetype = []<br />
dicttype = {'j':'.jpg','p':'.png','t':'.tif','g':'.gif','P':'.pdf','J':'.jpeg'}<br />
Dicttype = {'j':'.JPG','p':'.PNG','t':'.TIF','g':'.GIF','P':'.PDF','J':'.JPEG'}<br />
<br />
imagedir = valueDialog('Images','Enter the Image Directory')<br />
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')<br />
for t in imagetype[0:]:<br />
filetype.append(dicttype[t])<br />
filetype.append(Dicttype[t])<br />
<br />
D=[]<br />
d = os.listdir(imagedir)<br />
for file in d:<br />
for format in filetype:<br />
if file.endswith(format):<br />
D.append(file)<br />
D.sort()<br />
labelFont = "DejaVu Sans"<br />
# There are 8 pictures per page; xpos and ypos are the x,y coord of the upper left corners<br />
xpos = (25, 321) <br />
ypos = (42, 236, 430, 624)<br />
# This proportion is right for photographs (at least for my digital Olympus)<br />
pwidth = 250<br />
pheight = 187<br />
imagecount = 0<br />
if len(D) > 0:<br />
if newDoc(PAPER_A4, (10,10,20,20),PORTRAIT, 1, UNIT_POINTS, NOFACINGPAGES, FIRSTPAGERIGHT):<br />
while imagecount < len(D):<br />
if imagecount > 0:<br />
newPage(-1)<br />
# L is the frame at the top of each page showing the directory name<br />
L = createText(15, 20, 200, 20)<br />
setText("Dir: " + imagedir, L)<br />
setTextAlignment(ALIGN_LEFT, L)<br />
setFont(labelFont, L)<br />
setFontSize(10, L)<br />
# Here is where we're loading images into the page, eight at a time, then go back up for a newPage<br />
for yframe in ypos:<br />
for xframe in xpos:<br />
if imagecount < len(D):<br />
f = createImage(xframe, yframe, pwidth, pheight)<br />
loadImage(imagedir + '/' + D[imagecount], f)<br />
setScaleImageToFrame(scaletoframe=1, proportional=1, name=f)<br />
lenfilename = len(D[imagecount])<br />
Lpiclen = int(5.3 * lenfilename)<br />
# Lpic is the label for each picture, with position and length adjusted according to the text length<br />
# so if you change in font or its size, you may need to adjust this only approximate calculation<br />
Lpic = createText(xframe + (250 - Lpiclen), yframe + 172, Lpiclen, 15)<br />
setText(D[imagecount], Lpic)<br />
setTextAlignment(ALIGN_RIGHT, Lpic)<br />
setFont(labelFont, Lpic)<br />
setFontSize(8, Lpic)<br />
setFillColor("White", Lpic)<br />
imagecount = imagecount + 1<br />
<br />
setRedraw(1)<br />
redrawAll()<br />
<br />
else:<br />
result = messageBox ('Not Found','No Images found with\n this search selection',BUTTON_OK)<br />
<br />
</nowiki><br />
</pre><br />
<br />
== album_letter_2.py ==<br />
<br />
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.<br />
<br />
<pre><nowiki><br />
#!/usr/bin/env python<br />
<br />
"""<br />
This is scribalbum_letter.py. This script will load the images from a<br />
directory, creating a new document of US Letter size.<br />
<br />
USAGE: It is probably better not to already have any document in Scribus,<br />
since memory usage can become intense when a large number of images is<br />
used.<br />
<br />
You are first presented with a dialog to choose either 4 or 6 images per page.<br />
Next select a directory where your images are located. Finally, select the <br />
types of image files, using the code you see in the last dialog. <br />
NOTE: If you choose PDF, only the first page will be imported, and the PDF <br />
will be rasterized.<br />
<br />
AUTHOR: Gregory Pittman Original version: 2005.02.13, this version: 2008.07.23<br />
<br />
LICENSE: This program is free software; you can redistribute it and/or modify <br />
it under the terms of the GNU General Public License as published by the Free <br />
Software Foundation; either version 2 of the License, or (at your option) any <br />
later version.<br />
<br />
http://wiki.scribus.net/index.php/Automatic_import_of_images:_Versions_not_requiring_Tkinter<br />
<br />
========================================================================<br />
<br />
Modifications by Henry Hartley - September, 2009:<br />
<br />
* allow user to specify 4, 6, or 12 images per page, selected at run time<br />
* changed font to Garamond Regular but provide a dialog for the user to change this at run time<br />
* Image are arranged in one of these ways:<br />
<br />
1 2 1 2 1 2 3<br />
3 4 3 4 4 5 6<br />
5 6 7 8 9<br />
10 11 12<br />
<br />
* figure out if images are landscape or portrait and adjust frame accordingly<br />
* center labels under images<br />
* offset page somewhat for 3-hole punch when printed double sided<br />
* replaced dir at top of all pages to a title, specified at run time<br />
* added page numbers (alternating corners for double sided printing)<br />
* the Scribus progress indicator and status line show how many files have<br />
been imported<br />
<br />
Note: 8.5 by 11 inch page is 612 by 792 points<br />
<br />
If you convert all images to a size close to what is needed by this script <br />
before running it then the memory requirements are reduced. The goal is to<br />
get an image that is the same size or only slightly larger than the image <br />
frame at 300dpi. Depending upon the number of pictures per page, this will <br />
be one of the following sizes:<br />
<br />
4 per page: 758 by 1137 pixels (182 by 273 points at 300dpi)<br />
6 per page: 608 by 912 pixels (146 by 219 points at 300dpi)<br />
12 per page: 421 by 633 pixels (101 by 152 points at 300dpi)<br />
<br />
One way to do this is to create a sub-directory under your image directory <br />
called "small" and then running a perl one-liner as shown below (assuming <br />
both Perl and ImageMagick are installed, of course).<br />
<br />
Note that the double backslash after "small" is required on MS Windows.<br />
Replace with a forward slash on Linux. The 37% used here works just about <br />
right when resizing images starting life as the 2048 by 3072 pixel images <br />
produced by my EOS D10 camera. Adjust accordingly. Fractional percentages <br />
are allowed.<br />
<br />
perl -e "((print qq|$_\n|) && system(qq|convert -resample 300 $_ -resize 50% small\\$_|)) foreach (glob(qq|*.jpg|))"<br />
<br />
------------------------------------------------------------------------<br />
<br />
A few minor things:<br />
<br />
After running, I export to PDF. Scribus reports Text Overflow errors on<br />
many (or possibly all) of the text fields. These errors, it seems, may <br />
safely be ignored.<br />
<br />
Depending on your requirements, you may want to change the Compression<br />
Quality setting in the PDF export dialog to something other than Maximum.<br />
<br />
While this script will run on a large number of images, it slows down as<br />
it runs (on my relatively modest hardware) and you may need to break up<br />
large collections into parts.<br />
<br />
<br />
"""<br />
<br />
import scribus<br />
import os<br />
<br />
filetype = []<br />
dicttype = {'j':'.jpg','p':'.png','t':'.tif','g':'.gif','P':'.pdf'}<br />
Dicttype = {'j':'.JPG','p':'.PNG','t':'.TIF','g':'.GIF','P':'.PDF'}<br />
nrimages = '0'<br />
<br />
while (nrimages != '4') and (nrimages != '6') and (nrimages != '12') and (nrimages != 'c'):<br />
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')<br />
<br />
imagedir = scribus.fileDialog('Select Image Directory','Directories',isdir=True)<br />
<br />
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')<br />
<br />
gallerytitle = scribus.valueDialog('Gallery Title','Enter the title you want to appear on all pages','')<br />
<br />
labelFont = scribus.valueDialog('Font for Text','Enter the name of the font you would like to use throughout your document','Garamond Regular')<br />
<br />
for t in imagetype[0:]:<br />
filetype.append(dicttype[t])<br />
filetype.append(Dicttype[t])<br />
d = os.listdir(imagedir)<br />
D = []<br />
for file in d:<br />
for format in filetype:<br />
if file.endswith(format):<br />
D.append(file)<br />
D.sort()<br />
<br />
# All of these numbers can be adjusted but what is here seems to work pretty well<br />
# If you would like to add new a new page size or layout, add a new set of values<br />
# in this section rather than replacing an existing set.<br />
<br />
if nrimages == '4':<br />
marginX = 24<br />
marginY = 24<br />
<br />
# Image height and width<br />
iHorW = 273<br />
iVerW = 182<br />
iVerH = iHorW<br />
iHorH = iVerW<br />
<br />
# Gap sizes and page offsets<br />
gapW = 6<br />
gapH = 73<br />
xOffset = 12<br />
yOffset = 58<br />
<br />
# Page title text frame<br />
titleFS = 18<br />
titleX = marginX<br />
titleY = marginY<br />
titleW = iHorW + iHorW + gapW<br />
titleH = titleFS * 2<br />
<br />
# Image label text frame<br />
# Height is enough to allow a second line of text if desired.<br />
labelGap = 6<br />
labelFS = 12<br />
labelH = labelFS * 3<br />
<br />
# Page number text frame<br />
pNumFS = 12<br />
pNumY = 759<br />
pNumXt = 1<br />
pNumW = 18<br />
pNumH = pNumFS * 1.5<br />
<br />
H2V = int((iHorW-iHorH)/2)<br />
V2H = int((iVerH-iVerW)/2)<br />
<br />
xPosH = [marginX, marginX + iHorW + gapW, marginX, marginX + iHorW + gapW]<br />
yPosH = [marginY + yOffset + V2H, marginY + yOffset + V2H, marginY + yOffset + iVerH + gapH + V2H, marginY + yOffset + iVerH + gapH + V2H]<br />
xPosV = [marginX + H2V, marginX + iHorW + gapW + H2V, marginX + H2V, marginX + iHorW + gapW + H2V]<br />
yPosV = [marginY + yOffset, marginY + yOffset, marginY + yOffset + iVerH + gapH, marginY + yOffset + iVerH + gapH]<br />
imgID = [0, 1, 2, 3]<br />
imgRow = 2<br />
<br />
<br />
<br />
if nrimages == '6':<br />
marginX = 48<br />
marginY = 18<br />
<br />
# Image height and width<br />
iHorW = 219<br />
iVerW = 146<br />
iVerH = iHorW<br />
iHorH = iVerW<br />
<br />
# Gap sizes and page offsets<br />
gapW = 30<br />
gapH = 18<br />
xOffset = 48<br />
yOffset = 24<br />
<br />
# Page title text frame<br />
titleFS = 12<br />
titleX = marginX<br />
titleY = marginY<br />
titleW = iHorW + gapW + iHorW<br />
titleH = titleFS * 2<br />
<br />
# Image label text frame<br />
# Height is enough to allow a second line of text if desired.<br />
labelGap = 0<br />
labelFS = 7<br />
labelH = labelFS * 3<br />
<br />
# Page number text frame<br />
pNumFS = 8<br />
pNumY = 759<br />
pNumXt = 1<br />
pNumW = 18<br />
pNumH = pNumFS * 1.5<br />
<br />
H2V = int((iHorW-iHorH)/2)<br />
V2H = int((iVerH-iVerW)/2)<br />
<br />
# It's quite likely that these longs lists could be replaced by a formula.<br />
# If anyone has the time to do that, it would probably make this script easier<br />
# to maintain.<br />
xPosH = [marginX, marginX + iHorW + gapW, marginX, marginX + iHorW + gapW, marginX, marginX + iHorW + gapW]<br />
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]<br />
xPosV = [marginX + H2V, marginX + iHorW + gapW + H2V, marginX + H2V, marginX + iHorW + gapW + H2V, marginX + H2V, marginX + iHorW + gapW + H2V]<br />
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)]<br />
imgID = [0, 1, 2, 3, 4, 5]<br />
imgRow = 2<br />
<br />
<br />
<br />
if nrimages == '12':<br />
marginX = 36<br />
marginY = 36<br />
<br />
# Image height and width<br />
iHorW = 152<br />
iVerW = 101<br />
iVerH = iHorW<br />
iHorH = iVerW<br />
<br />
# Gap sizes and page offsets<br />
gapW = 24<br />
gapH = 21<br />
xOffset = 36<br />
yOffset = 24<br />
<br />
# Page title text frame<br />
titleFS = 12<br />
titleX = marginX<br />
titleY = marginY<br />
titleW = iHorW + iHorW + gapW + iHorW + gapW<br />
titleH = titleFS * 2<br />
<br />
# Image label text frame<br />
# Height is enough to allow a second line of text if desired.<br />
labelGap = 0<br />
labelFS = 7<br />
labelH = labelFS * 3<br />
<br />
# Page number text frame<br />
pNumFS = 8<br />
pNumY = 759<br />
pNumXt = 2<br />
pNumW = 18<br />
pNumH = pNumFS * 1.5<br />
<br />
H2V = int((iHorW-iHorH)/2)<br />
V2H = int((iVerH-iVerW)/2)<br />
<br />
# It's quite likely that these longs lists could be replaced by a formula.<br />
# If anyone has the time to do that, it would probably make this script easier<br />
# to maintain.<br />
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)]<br />
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]<br />
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]<br />
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)]<br />
imgID = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]<br />
imgRow = 3<br />
<br />
<br />
# EXTRA CATEGORY - By putting this in I have a place to put temporary numbers <br />
# for one of a kind collections. For instance, the parameters above assume that<br />
# images will have the 3:2 aspect ratio of 35mm film or most digital camera <br />
# images. The numbers used here are slightly modified to work with images scanned <br />
# from 4x5 inch negatives.<br />
<br />
if nrimages == 'c':<br />
marginX = 36<br />
marginY = 48<br />
<br />
# Image height and width<br />
iHorW = 125<br />
iVerW = 100<br />
iVerH = iHorW<br />
iHorH = iVerW<br />
<br />
# Gap sizes and page offsets<br />
gapW = 60<br />
gapH = 45<br />
xOffset = 39<br />
yOffset = 36<br />
<br />
# Page title text frame<br />
titleFS = 12<br />
titleX = marginX<br />
titleY = marginY<br />
titleW = iHorW + iHorW + gapW + iHorW + gapW<br />
titleH = titleFS * 2<br />
<br />
# Image label text frame<br />
# Height is enough to allow a second line of text if desired.<br />
labelGap = 0<br />
labelFS = 7<br />
labelH = labelFS * 3<br />
<br />
# Page number text frame<br />
pNumFS = 8<br />
pNumY = 759<br />
pNumXt = 2<br />
pNumW = 18<br />
pNumH = pNumFS * 1.5<br />
<br />
H2V = int((iHorW-iHorH)/2)<br />
V2H = int((iVerH-iVerW)/2)<br />
<br />
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)]<br />
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]<br />
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]<br />
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)]<br />
imgID = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]<br />
imgRow = 3<br />
<br />
imageCount = 0<br />
pageNumber = 1<br />
scribus.progressTotal(len(D))<br />
if len(D) > 0:<br />
if scribus.newDoc(scribus.PAPER_LETTER, (marginX, marginX, marginY, marginY),scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.NOFACINGPAGES, scribus.FIRSTPAGERIGHT):<br />
while imageCount < len(D):<br />
if imageCount > 0:<br />
scribus.newPage(-1)<br />
<br />
# Here is where we're loading images into the page, four, six, or twelve at a time, then go back up for a newPage<br />
if pageNumber % 2 == 0:<br />
pOffset = 0<br />
pNumX = xPosH[0]<br />
else:<br />
pOffset = xOffset<br />
pNumX = xPosH[pNumXt] + iHorW + pOffset - pNumW<br />
<br />
# L is the frame at the top of each page showing the gallery title (read in above)<br />
L = scribus.createText(titleX + pOffset, titleY, titleW, titleH)<br />
scribus.setText(gallerytitle, L)<br />
scribus.setTextAlignment(scribus.ALIGN_CENTERED, L)<br />
scribus.setFont(labelFont, L)<br />
scribus.setFontSize(titleFS, L)<br />
<br />
for i in imgID:<br />
if imageCount < len(D):<br />
<br />
scribus.statusMessage("Placing image " + D[imageCount] + " in document (" + `imageCount` + " of " + `len(D)` + ")")<br />
scribus.progressSet(imageCount)<br />
<br />
# Create a temporary image object. Size and location are irrelivant<br />
tempImage = scribus.createImage(10, 10, 10, 10)<br />
<br />
# Populate that object with your image<br />
scribus.loadImage(imagedir + '/' + D[imageCount], tempImage)<br />
<br />
# Scale the image but NOT proportionally<br />
scribus.setScaleImageToFrame(scaletoframe=1, proportional=0, name=tempImage)<br />
<br />
# Use getImageScale to get the relative scaling in the x and y directions<br />
imgx,imgy = scribus.getImageScale(tempImage)<br />
<br />
# If imgx < imgy, you have an horizontal image, otherwise, <br />
# a vertical (or square) image. <br />
if imgx < imgy:<br />
x = xPosH[i] + pOffset<br />
y = yPosH[i]<br />
pWidth = iHorW<br />
pHeight = iHorH<br />
else:<br />
x = xPosV[i] + pOffset<br />
y = yPosV[i]<br />
pWidth = iVerW<br />
pHeight = iVerH<br />
<br />
# Can't have these cluttering up the page<br />
scribus.deleteObject(tempImage)<br />
<br />
# Now we create the REAL image object placed appropriately<br />
f = scribus.createImage(x, y, pWidth, pHeight)<br />
<br />
# and load the image<br />
scribus.loadImage(imagedir + '/' + D[imageCount], f)<br />
<br />
# this time when we scale the image, we do it proportionally<br />
scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=f)<br />
<br />
# Lpic is the label for each picture, the position is the same for all <br />
# image orientations and the labels are centered under the pictures.<br />
<br />
# Create the text frame.<br />
Lpic = scribus.createText(xPosH[i] + pOffset, yPosV[i] + iVerH + labelGap, iHorW, labelH)<br />
<br />
# populate with the file name<br />
scribus.setText(D[imageCount], Lpic)<br />
<br />
# and format as desired<br />
scribus.setTextAlignment(scribus.ALIGN_CENTERED, Lpic)<br />
scribus.setFont(labelFont, Lpic)<br />
scribus.setFontSize(labelFS, Lpic)<br />
<br />
# increment the image count<br />
imageCount += 1<br />
<br />
# Now the page number<br />
<br />
# Create a text frame<br />
pNum = scribus.createText(pNumX, pNumY, pNumW, pNumH)<br />
<br />
# Put the page number in it and format<br />
scribus.setText(`pageNumber`, pNum)<br />
if imageCount < len(D):<br />
scribus.setTextAlignment(scribus.ALIGN_RIGHT, pNum)<br />
else:<br />
scribus.setTextAlignment(scribus.ALIGN_LEFT, pNum)<br />
scribus.setFont(labelFont, pNum)<br />
scribus.setFontSize(pNumFS, pNum)<br />
<br />
# Finally, we increment the page number<br />
pageNumber += 1<br />
scribus.setRedraw(1)<br />
scribus.redrawAll()<br />
<br />
else:<br />
result = scribus.messageBox ('Not Found','No Images found with\n this search selection',scribus.BUTTON_OK)<br />
<br />
scribus.setRedraw(1)<br />
scribus.redrawAll()<br />
<br />
scribus.statusMessage("")<br />
scribus.progressReset()<br />
<br />
</nowiki></pre></div>Hhartleyhttps://wiki.scribus.net/wiki/index.php?title=Automatic_import_of_images:_Versions_not_requiring_Tkinter&diff=21277Automatic import of images: Versions not requiring Tkinter2009-10-01T20:06:12Z<p>Hhartley: /* album_letter_2.py */ Add a few comments to code</p>
<hr />
<div>{{Scripting Index}}<br />
<br />
==scribalbum_letter.py==<br />
<br />
Link to: [[Automatic import of images from a directory using a script]]<br />
<br />
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.<br />
<br />
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.<br />
<br />
Some rewriting was done so that this works with Scribus version 1.3.5svn, and the default font was changed to DejaVu Sans &ndash; if you want to use a different one, look for the <tt>labelFont</tt> variable assignment. This version of scribalbum_letter also works with Scribus 1.3.3.x.<br />
<br />
<pre><br />
#!/usr/bin/env python<br />
<br />
"""<br />
This is scribalbum_letter.py. This script will load the images from a<br />
directory, creating a new document of US Letter size.<br />
<br />
USAGE: It is probably better not to already have any document in Scribus,<br />
since memory usage can become intense when a large number of images is<br />
used. <br />
You are first presented with a dialog to choose either 4 or 6 images per page.<br />
Next select a directory where your images are located. Finally, select the <br />
types of image files, using the code you see in the last dialog. <br />
NOTE: If you choose PDF, only the first page will be imported, and the PDF <br />
will be rasterized.<br />
<br />
AUTHOR: Gregory Pittman Original version: 2005.02.13, this version: 2008.07.23<br />
<br />
LICENSE: This program is free software; you can redistribute it and/or modify <br />
it under the terms of the GNU General Public License as published by the Free <br />
Software Foundation; either version 2 of the License, or (at your option) any <br />
later version.<br />
<br />
"""<br />
<br />
import scribus<br />
import os<br />
<br />
filetype = []<br />
dicttype = {'j':'.jpg','p':'.png','t':'.tif','g':'.gif','P':'.pdf'}<br />
Dicttype = {'j':'.JPG','p':'.PNG','t':'.TIF','g':'.GIF','P':'.PDF'}<br />
nrimages = '0'<br />
while (nrimages != '4') and (nrimages != '6'):<br />
nrimages = scribus.valueDialog('Pictures','- US Letter Paper -\n Four or Six Images per Page?\nChange to 6 as desired','4')<br />
imagedir = scribus.fileDialog('Select Image Directory','Directories',isdir=True)<br />
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')<br />
for t in imagetype[0:]:<br />
filetype.append(dicttype[t])<br />
filetype.append(Dicttype[t])<br />
d = os.listdir(imagedir)<br />
D = []<br />
for file in d:<br />
for format in filetype:<br />
if file.endswith(format):<br />
D.append(file)<br />
D.sort()<br />
labelFont="DejaVu Sans Book"<br />
<br />
# When 4 pics per page, coords are: (15, 42),(310, 187), (15, 388), (310, 533)<br />
# When 6 pics per page: (15, 42),(310, 42), (15, 290), (310, 290),(15,533),(310,533)<br />
if nrimages == '4':<br />
xpos = [15, 310, 15, 310] <br />
ypos = [42, 187, 388, 533]<br />
if nrimages == '6':<br />
xpos = [15, 310, 15, 310, 15, 310]<br />
ypos = [42, 42, 290, 290, 533, 533]<br />
# This proportion is right for photographs from my digital camera<br />
pwidth = 288<br />
pheight = 193<br />
imagecount = 0<br />
#framecount = 0<br />
if len(D) > 0:<br />
if scribus.newDoc(scribus.PAPER_LETTER, (10,10,20,20),scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.NOFACINGPAGES, scribus.FIRSTPAGERIGHT):<br />
while imagecount < len(D):<br />
if imagecount > 0:<br />
scribus.newPage(-1)<br />
framecount = 0<br />
# L is the frame at the top of each page showing the directory name<br />
L = scribus.createText(15, 20, 200, 20)<br />
scribus.setText("Dir: " + imagedir, L)<br />
scribus.setTextAlignment(scribus.ALIGN_LEFT, L)<br />
scribus.setFont(labelFont, L)<br />
scribus.setFontSize(10, L)<br />
# Here is where we're loading images into the page, four at a time, then go back up for a newPage<br />
for x,y in zip(xpos,ypos):<br />
if imagecount < len(D):<br />
f = scribus.createImage(x, y, pwidth, pheight)<br />
scribus.loadImage(imagedir + '/' + D[imagecount], f)<br />
scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=f)<br />
lenfilename = len(D[imagecount])<br />
Lpiclen = int(5.3 * lenfilename)<br />
# Lpic is the label for each picture, with position and length adjusted<br />
# according to the text length, so if you change the font or its size,<br />
# you may need to adjust this only approximate calculation.<br />
Lpic = scribus.createText(x, y + 193, Lpiclen, 15)<br />
scribus.setText(D[imagecount], Lpic)<br />
scribus.setTextAlignment(scribus.ALIGN_RIGHT, Lpic)<br />
scribus.setFont(labelFont, Lpic)<br />
scribus.setFontSize(8, Lpic)<br />
scribus.setFillColor("White", Lpic)<br />
imagecount += 1<br />
<br />
scribus.setRedraw(1)<br />
scribus.redrawAll()<br />
<br />
else:<br />
result = scribus.messageBox ('Not Found','No Images found with\n this search selection',scribus.BUTTON_OK)<br />
</pre><br />
<br />
==scribalbum_a4.py==<br />
<br />
This is the version that puts 8 images on A4 paper, with little extra space. Usage is as above.<br />
<br />
<pre><br />
<nowiki><br />
#!/usr/bin/env python<br />
<br />
# File: scribalbum_a4.py<br />
# originally 2005.02.13 Gregory Pittman<br />
# this version 2006.03.17 does without Tkinter<br />
# Uses valueDialog() for data entry of directory name<br />
# and also mnemonics for image types, j=jpg, and so on.<br />
# Also searches for uppercase equivalents.<br />
# Makes a new document<br />
<br />
from scribus import *<br />
import os<br />
<br />
filetype = []<br />
dicttype = {'j':'.jpg','p':'.png','t':'.tif','g':'.gif','P':'.pdf','J':'.jpeg'}<br />
Dicttype = {'j':'.JPG','p':'.PNG','t':'.TIF','g':'.GIF','P':'.PDF','J':'.JPEG'}<br />
<br />
imagedir = valueDialog('Images','Enter the Image Directory')<br />
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')<br />
for t in imagetype[0:]:<br />
filetype.append(dicttype[t])<br />
filetype.append(Dicttype[t])<br />
<br />
D=[]<br />
d = os.listdir(imagedir)<br />
for file in d:<br />
for format in filetype:<br />
if file.endswith(format):<br />
D.append(file)<br />
D.sort()<br />
labelFont = "DejaVu Sans"<br />
# There are 8 pictures per page; xpos and ypos are the x,y coord of the upper left corners<br />
xpos = (25, 321) <br />
ypos = (42, 236, 430, 624)<br />
# This proportion is right for photographs (at least for my digital Olympus)<br />
pwidth = 250<br />
pheight = 187<br />
imagecount = 0<br />
if len(D) > 0:<br />
if newDoc(PAPER_A4, (10,10,20,20),PORTRAIT, 1, UNIT_POINTS, NOFACINGPAGES, FIRSTPAGERIGHT):<br />
while imagecount < len(D):<br />
if imagecount > 0:<br />
newPage(-1)<br />
# L is the frame at the top of each page showing the directory name<br />
L = createText(15, 20, 200, 20)<br />
setText("Dir: " + imagedir, L)<br />
setTextAlignment(ALIGN_LEFT, L)<br />
setFont(labelFont, L)<br />
setFontSize(10, L)<br />
# Here is where we're loading images into the page, eight at a time, then go back up for a newPage<br />
for yframe in ypos:<br />
for xframe in xpos:<br />
if imagecount < len(D):<br />
f = createImage(xframe, yframe, pwidth, pheight)<br />
loadImage(imagedir + '/' + D[imagecount], f)<br />
setScaleImageToFrame(scaletoframe=1, proportional=1, name=f)<br />
lenfilename = len(D[imagecount])<br />
Lpiclen = int(5.3 * lenfilename)<br />
# Lpic is the label for each picture, with position and length adjusted according to the text length<br />
# so if you change in font or its size, you may need to adjust this only approximate calculation<br />
Lpic = createText(xframe + (250 - Lpiclen), yframe + 172, Lpiclen, 15)<br />
setText(D[imagecount], Lpic)<br />
setTextAlignment(ALIGN_RIGHT, Lpic)<br />
setFont(labelFont, Lpic)<br />
setFontSize(8, Lpic)<br />
setFillColor("White", Lpic)<br />
imagecount = imagecount + 1<br />
<br />
setRedraw(1)<br />
redrawAll()<br />
<br />
else:<br />
result = messageBox ('Not Found','No Images found with\n this search selection',BUTTON_OK)<br />
<br />
</nowiki><br />
</pre><br />
<br />
== album_letter_2.py ==<br />
<br />
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.<br />
<br />
<pre><nowiki><br />
#!/usr/bin/env python<br />
<br />
"""<br />
This is scribalbum_letter.py. This script will load the images from a<br />
directory, creating a new document of US Letter size.<br />
<br />
USAGE: It is probably better not to already have any document in Scribus,<br />
since memory usage can become intense when a large number of images is<br />
used.<br />
<br />
You are first presented with a dialog to choose either 4 or 6 images per page.<br />
Next select a directory where your images are located. Finally, select the <br />
types of image files, using the code you see in the last dialog. <br />
NOTE: If you choose PDF, only the first page will be imported, and the PDF <br />
will be rasterized.<br />
<br />
AUTHOR: Gregory Pittman Original version: 2005.02.13, this version: 2008.07.23<br />
<br />
LICENSE: This program is free software; you can redistribute it and/or modify <br />
it under the terms of the GNU General Public License as published by the Free <br />
Software Foundation; either version 2 of the License, or (at your option) any <br />
later version.<br />
<br />
http://wiki.scribus.net/index.php/Automatic_import_of_images:_Versions_not_requiring_Tkinter<br />
<br />
========================================================================<br />
<br />
Modifications by Henry Hartley - September, 2009:<br />
<br />
* allow user to specify 4, 6, or 12 images per page, selected at run time<br />
* changed font to Garamond Regular but provide a dialog for the user to change this at run time<br />
* Image are arranged in one of these ways:<br />
<br />
1 2 1 2 1 2 3<br />
3 4 3 4 4 5 6<br />
5 6 7 8 9<br />
10 11 12<br />
<br />
* figure out if images are landscape or portrait and adjust frame accordingly<br />
* center labels under images<br />
* offset page somewhat for 3-hole punch when printed double sided<br />
* replaced dir at top of all pages to a title, specified at run time<br />
* added page numbers (alternating corners for double sided printing)<br />
* the Scribus progress indicator and status line show how many files have<br />
been imported<br />
<br />
Note: 8.5 by 11 inch page is 612 by 792 points<br />
<br />
If you convert all images to a size close to what is needed by this script <br />
before running it then the memory requirements are reduced. The goal is to<br />
get an image that is the same size or only slightly larger than the image <br />
frame at 300dpi. Depending upon the number of pictures per page, this will <br />
be one of the following sizes:<br />
<br />
4 per page: 758 by 1137 pixels (182 by 273 points at 300dpi)<br />
6 per page: 608 by 912 pixels (146 by 219 points at 300dpi)<br />
12 per page: 421 by 633 pixels (101 by 152 points at 300dpi)<br />
<br />
One way to do this is to create a sub-directory under your image directory <br />
called "small" and then running a perl one-liner as shown below (assuming <br />
both Perl and ImageMagick are installed, of course).<br />
<br />
Note that the double backslash after "small" is required on MS Windows.<br />
Replace with a forward slash on Linux. The 37% used here works just about <br />
right when resizing images starting life as the 2048 by 3072 pixel images <br />
produced by my EOS D10 camera. Adjust accordingly. Fractional percentages <br />
are allowed.<br />
<br />
perl -e "((print qq|$_\n|) && system(qq|convert -resample 300 $_ -resize 50% small\\$_|)) foreach (glob(qq|*.jpg|))"<br />
<br />
------------------------------------------------------------------------<br />
<br />
A few minor things:<br />
<br />
After running, I export to PDF. Scribus reports Text Overflow errors on<br />
many (or possibly all) of the text fields. These errors, it seems, may <br />
safely be ignored.<br />
<br />
Depending on your requirements, you may want to change the Compression<br />
Quality setting in the PDF export dialog to something other than Maximum.<br />
<br />
While this script will run on a large number of images, it slows down as<br />
it runs (on my relatively modest hardware) and you may need to break up<br />
large collections into parts.<br />
<br />
<br />
"""<br />
<br />
import scribus<br />
import os<br />
<br />
filetype = []<br />
dicttype = {'j':'.jpg','p':'.png','t':'.tif','g':'.gif','P':'.pdf'}<br />
Dicttype = {'j':'.JPG','p':'.PNG','t':'.TIF','g':'.GIF','P':'.PDF'}<br />
nrimages = '0'<br />
<br />
while (nrimages != '4') and (nrimages != '6') and (nrimages != '12') and (nrimages != 'c'):<br />
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')<br />
<br />
imagedir = scribus.fileDialog('Select Image Directory','Directories',isdir=True)<br />
<br />
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')<br />
<br />
gallerytitle = scribus.valueDialog('Gallery Title','Enter the title you want to appear on all pages','')<br />
<br />
labelFont = scribus.valueDialog('Font for Text','Enter the name of the font you would like to use throughout your document','Garamond Regular')<br />
<br />
for t in imagetype[0:]:<br />
filetype.append(dicttype[t])<br />
filetype.append(Dicttype[t])<br />
d = os.listdir(imagedir)<br />
D = []<br />
for file in d:<br />
for format in filetype:<br />
if file.endswith(format):<br />
D.append(file)<br />
D.sort()<br />
<br />
# All of these numbers can be adjusted but what is here seems to work pretty well<br />
# If you would like to add new a new page size or layout, add a new set of values<br />
# in this section rather than replacing an existing set.<br />
<br />
if nrimages == '4':<br />
marginX = 24<br />
marginY = 24<br />
<br />
# Image height and width<br />
iHorW = 273<br />
iVerW = 182<br />
iVerH = iHorW<br />
iHorH = iVerW<br />
<br />
# Gap sizes and page offsets<br />
gapW = 6<br />
gapH = 73<br />
xOffset = 12<br />
yOffset = 58<br />
<br />
# Page title text frame<br />
titleFS = 18<br />
titleX = marginX<br />
titleY = marginY<br />
titleW = iHorW + iHorW + gapW<br />
titleH = titleFS * 2<br />
<br />
# Image label text frame<br />
# Height is enough to allow a second line of text if desired.<br />
labelGap = 6<br />
labelFS = 12<br />
labelH = labelFS * 3<br />
<br />
# Page number text frame<br />
pNumFS = 12<br />
pNumY = 759<br />
pNumXt = 1<br />
pNumW = 18<br />
pNumH = pNumFS * 1.5<br />
<br />
H2V = int((iHorW-iHorH)/2)<br />
V2H = int((iVerH-iVerW)/2)<br />
<br />
xPosH = [marginX, marginX + iHorW + gapW, marginX, marginX + iHorW + gapW]<br />
yPosH = [marginY + yOffset + V2H, marginY + yOffset + V2H, marginY + yOffset + iVerH + gapH + V2H, marginY + yOffset + iVerH + gapH + V2H]<br />
xPosV = [marginX + H2V, marginX + iHorW + gapW + H2V, marginX + H2V, marginX + iHorW + gapW + H2V]<br />
yPosV = [marginY + yOffset, marginY + yOffset, marginY + yOffset + iVerH + gapH, marginY + yOffset + iVerH + gapH]<br />
imgID = [0, 1, 2, 3]<br />
imgRow = 2<br />
<br />
<br />
<br />
if nrimages == '6':<br />
marginX = 48<br />
marginY = 18<br />
<br />
# Image height and width<br />
iHorW = 219<br />
iVerW = 146<br />
iVerH = iHorW<br />
iHorH = iVerW<br />
<br />
# Gap sizes and page offsets<br />
gapW = 30<br />
gapH = 18<br />
xOffset = 48<br />
yOffset = 24<br />
<br />
# Page title text frame<br />
titleFS = 12<br />
titleX = marginX<br />
titleY = marginY<br />
titleW = iHorW + gapW + iHorW<br />
titleH = titleFS * 2<br />
<br />
# Image label text frame<br />
# Height is enough to allow a second line of text if desired.<br />
labelGap = 0<br />
labelFS = 7<br />
labelH = labelFS * 3<br />
<br />
# Page number text frame<br />
pNumFS = 8<br />
pNumY = 759<br />
pNumXt = 1<br />
pNumW = 18<br />
pNumH = pNumFS * 1.5<br />
<br />
H2V = int((iHorW-iHorH)/2)<br />
V2H = int((iVerH-iVerW)/2)<br />
<br />
# It's quite likely that these longs lists could be replaced by a formula.<br />
# If anyone has the time to do that, it would probably make this script easier<br />
# to maintain.<br />
xPosH = [marginX, marginX + iHorW + gapW, marginX, marginX + iHorW + gapW, marginX, marginX + iHorW + gapW]<br />
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]<br />
xPosV = [marginX + H2V, marginX + iHorW + gapW + H2V, marginX + H2V, marginX + iHorW + gapW + H2V, marginX + H2V, marginX + iHorW + gapW + H2V]<br />
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)]<br />
imgID = [0, 1, 2, 3, 4, 5]<br />
imgRow = 2<br />
<br />
<br />
<br />
if nrimages == '12':<br />
marginX = 36<br />
marginY = 36<br />
<br />
# Image height and width<br />
iHorW = 152<br />
iVerW = 101<br />
iVerH = iHorW<br />
iHorH = iVerW<br />
<br />
# Gap sizes and page offsets<br />
gapW = 24<br />
gapH = 21<br />
xOffset = 36<br />
yOffset = 24<br />
<br />
# Page title text frame<br />
titleFS = 12<br />
titleX = marginX<br />
titleY = marginY<br />
titleW = iHorW + iHorW + gapW + iHorW + gapW<br />
titleH = titleFS * 2<br />
<br />
# Image label text frame<br />
# Height is enough to allow a second line of text if desired.<br />
labelGap = 0<br />
labelFS = 7<br />
labelH = labelFS * 3<br />
<br />
# Page number text frame<br />
pNumFS = 8<br />
pNumY = 759<br />
pNumXt = 2<br />
pNumW = 18<br />
pNumH = pNumFS * 1.5<br />
<br />
H2V = int((iHorW-iHorH)/2)<br />
V2H = int((iVerH-iVerW)/2)<br />
<br />
# It's quite likely that these longs lists could be replaced by a formula.<br />
# If anyone has the time to do that, it would probably make this script easier<br />
# to maintain.<br />
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)]<br />
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]<br />
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]<br />
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)]<br />
imgID = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]<br />
imgRow = 3<br />
<br />
<br />
# EXTRA CATEGORY - By putting this in I have a place to put temporary numbers <br />
# for one of a kind collections. For instance, the parameters above assume that<br />
# images will have the 3:2 aspect ratio of 35mm film or most digital camera <br />
# images. The numbers used here are slightly modified to work with images scanned <br />
# from 4x5 inch negatives.<br />
<br />
if nrimages == 'c':<br />
marginX = 36<br />
marginY = 48<br />
<br />
# Image height and width<br />
iHorW = 125<br />
iVerW = 100<br />
iVerH = iHorW<br />
iHorH = iVerW<br />
<br />
# Gap sizes and page offsets<br />
gapW = 60<br />
gapH = 45<br />
xOffset = 39<br />
yOffset = 36<br />
<br />
# Page title text frame<br />
titleFS = 12<br />
titleX = marginX<br />
titleY = marginY<br />
titleW = iHorW + iHorW + gapW + iHorW + gapW<br />
titleH = titleFS * 2<br />
<br />
# Image label text frame<br />
# Height is enough to allow a second line of text if desired.<br />
labelGap = 0<br />
labelFS = 7<br />
labelH = labelFS * 3<br />
<br />
# Page number text frame<br />
pNumFS = 8<br />
pNumY = 759<br />
pNumXt = 2<br />
pNumW = 18<br />
pNumH = pNumFS * 1.5<br />
<br />
H2V = int((iHorW-iHorH)/2)<br />
V2H = int((iVerH-iVerW)/2)<br />
<br />
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)]<br />
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]<br />
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]<br />
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)]<br />
imgID = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]<br />
imgRow = 3<br />
<br />
imageCount = 0<br />
pageNumber = 1<br />
scribus.progressTotal(len(D))<br />
if len(D) > 0:<br />
if scribus.newDoc(scribus.PAPER_LETTER, (marginX, marginX, marginY, marginY),scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.NOFACINGPAGES, scribus.FIRSTPAGERIGHT):<br />
while imageCount < len(D):<br />
if imageCount > 0:<br />
scribus.newPage(-1)<br />
<br />
# Here is where we're loading images into the page, four, six, or twelve at a time, then go back up for a newPage<br />
if pageNumber % 2 == 0:<br />
pOffset = 0<br />
pNumX = xPosH[0]<br />
else:<br />
pOffset = xOffset<br />
pNumX = xPosH[pNumXt] + iHorW + pOffset - pNumW<br />
<br />
# L is the frame at the top of each page showing the gallery title (read in above)<br />
L = scribus.createText(titleX + pOffset, titleY, titleW, titleH)<br />
scribus.setText(gallerytitle, L)<br />
scribus.setTextAlignment(scribus.ALIGN_CENTERED, L)<br />
scribus.setFont(labelFont, L)<br />
scribus.setFontSize(titleFS, L)<br />
<br />
for i in imgID:<br />
if imageCount < len(D):<br />
<br />
scribus.statusMessage("Placing image " + D[imageCount] + " in document (" + `imageCount` + " of " + `len(D)` + ")")<br />
scribus.progressSet(imageCount)<br />
<br />
# Create a temporary image object. Size and location are irrelivant<br />
tempImage = scribus.createImage(10, 10, 10, 10)<br />
<br />
# Populate that object with your image<br />
scribus.loadImage(imagedir + '/' + D[imageCount], tempImage)<br />
<br />
# Scale the image but NOT proportionally<br />
scribus.setScaleImageToFrame(scaletoframe=1, proportional=0, name=tempImage)<br />
<br />
# Use getImageScale to get the relative scaling in the x and y directions<br />
imgx,imgy = scribus.getImageScale(tempImage)<br />
<br />
# If imgx < imgy, you have an horizontal image, otherwise, <br />
# a vertical (or square) image. <br />
if imgx < imgy:<br />
x = xPosH[i] + pOffset<br />
y = yPosH[i]<br />
pWidth = iHorW<br />
pHeight = iHorH<br />
else:<br />
x = xPosV[i] + pOffset<br />
y = yPosV[i]<br />
pWidth = iVerW<br />
pHeight = iVerH<br />
<br />
# Can't have these cluttering up the page<br />
scribus.deleteObject(tempImage)<br />
<br />
# Now we create the REAL image object placed appropriately<br />
f = scribus.createImage(x, y, pWidth, pHeight)<br />
<br />
# and load the image<br />
scribus.loadImage(imagedir + '/' + D[imageCount], f)<br />
<br />
# this time when we scale the image, we do it proportionally<br />
scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=f)<br />
<br />
# Lpic is the label for each picture, the position is the same for all <br />
# image orientations and the labels are centered under the pictures.<br />
<br />
# Create the text frame.<br />
Lpic = scribus.createText(xPosH[i] + pOffset, yPosV[i] + iVerH + labelGap, iHorW, labelH)<br />
<br />
# populate with the file name<br />
scribus.setText(D[imageCount], Lpic)<br />
<br />
# and format as desired<br />
scribus.setTextAlignment(scribus.ALIGN_CENTERED, Lpic)<br />
scribus.setFont(labelFont, Lpic)<br />
scribus.setFontSize(labelFS, Lpic)<br />
scribus.setFillColor("White", Lpic)<br />
<br />
# increment the image count<br />
imageCount += 1<br />
<br />
# Now the page number<br />
<br />
# Create a text frame<br />
pNum = scribus.createText(pNumX, pNumY, pNumW, pNumH)<br />
<br />
# Put the page number in it and format<br />
scribus.setText(`pageNumber`, pNum)<br />
if imageCount < len(D):<br />
scribus.setTextAlignment(scribus.ALIGN_RIGHT, pNum)<br />
else:<br />
scribus.setTextAlignment(scribus.ALIGN_LEFT, pNum)<br />
scribus.setFont(labelFont, pNum)<br />
scribus.setFontSize(pNumFS, pNum)<br />
scribus.setFillColor("White", pNum)<br />
<br />
# Finally, we increment the page number<br />
pageNumber += 1<br />
scribus.setRedraw(1)<br />
scribus.redrawAll()<br />
<br />
else:<br />
result = scribus.messageBox ('Not Found','No Images found with\n this search selection',scribus.BUTTON_OK)<br />
<br />
scribus.setRedraw(1)<br />
scribus.redrawAll()<br />
<br />
scribus.statusMessage("")<br />
scribus.progressReset()<br />
<br />
</nowiki></pre></div>Hhartleyhttps://wiki.scribus.net/wiki/index.php?title=Automatic_import_of_images:_Versions_not_requiring_Tkinter&diff=21276Automatic import of images: Versions not requiring Tkinter2009-10-01T19:51:59Z<p>Hhartley: Add new album_letter_2.py</p>
<hr />
<div>{{Scripting Index}}<br />
<br />
==scribalbum_letter.py==<br />
<br />
Link to: [[Automatic import of images from a directory using a script]]<br />
<br />
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.<br />
<br />
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.<br />
<br />
Some rewriting was done so that this works with Scribus version 1.3.5svn, and the default font was changed to DejaVu Sans &ndash; if you want to use a different one, look for the <tt>labelFont</tt> variable assignment. This version of scribalbum_letter also works with Scribus 1.3.3.x.<br />
<br />
<pre><br />
#!/usr/bin/env python<br />
<br />
"""<br />
This is scribalbum_letter.py. This script will load the images from a<br />
directory, creating a new document of US Letter size.<br />
<br />
USAGE: It is probably better not to already have any document in Scribus,<br />
since memory usage can become intense when a large number of images is<br />
used. <br />
You are first presented with a dialog to choose either 4 or 6 images per page.<br />
Next select a directory where your images are located. Finally, select the <br />
types of image files, using the code you see in the last dialog. <br />
NOTE: If you choose PDF, only the first page will be imported, and the PDF <br />
will be rasterized.<br />
<br />
AUTHOR: Gregory Pittman Original version: 2005.02.13, this version: 2008.07.23<br />
<br />
LICENSE: This program is free software; you can redistribute it and/or modify <br />
it under the terms of the GNU General Public License as published by the Free <br />
Software Foundation; either version 2 of the License, or (at your option) any <br />
later version.<br />
<br />
"""<br />
<br />
import scribus<br />
import os<br />
<br />
filetype = []<br />
dicttype = {'j':'.jpg','p':'.png','t':'.tif','g':'.gif','P':'.pdf'}<br />
Dicttype = {'j':'.JPG','p':'.PNG','t':'.TIF','g':'.GIF','P':'.PDF'}<br />
nrimages = '0'<br />
while (nrimages != '4') and (nrimages != '6'):<br />
nrimages = scribus.valueDialog('Pictures','- US Letter Paper -\n Four or Six Images per Page?\nChange to 6 as desired','4')<br />
imagedir = scribus.fileDialog('Select Image Directory','Directories',isdir=True)<br />
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')<br />
for t in imagetype[0:]:<br />
filetype.append(dicttype[t])<br />
filetype.append(Dicttype[t])<br />
d = os.listdir(imagedir)<br />
D = []<br />
for file in d:<br />
for format in filetype:<br />
if file.endswith(format):<br />
D.append(file)<br />
D.sort()<br />
labelFont="DejaVu Sans Book"<br />
<br />
# When 4 pics per page, coords are: (15, 42),(310, 187), (15, 388), (310, 533)<br />
# When 6 pics per page: (15, 42),(310, 42), (15, 290), (310, 290),(15,533),(310,533)<br />
if nrimages == '4':<br />
xpos = [15, 310, 15, 310] <br />
ypos = [42, 187, 388, 533]<br />
if nrimages == '6':<br />
xpos = [15, 310, 15, 310, 15, 310]<br />
ypos = [42, 42, 290, 290, 533, 533]<br />
# This proportion is right for photographs from my digital camera<br />
pwidth = 288<br />
pheight = 193<br />
imagecount = 0<br />
#framecount = 0<br />
if len(D) > 0:<br />
if scribus.newDoc(scribus.PAPER_LETTER, (10,10,20,20),scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.NOFACINGPAGES, scribus.FIRSTPAGERIGHT):<br />
while imagecount < len(D):<br />
if imagecount > 0:<br />
scribus.newPage(-1)<br />
framecount = 0<br />
# L is the frame at the top of each page showing the directory name<br />
L = scribus.createText(15, 20, 200, 20)<br />
scribus.setText("Dir: " + imagedir, L)<br />
scribus.setTextAlignment(scribus.ALIGN_LEFT, L)<br />
scribus.setFont(labelFont, L)<br />
scribus.setFontSize(10, L)<br />
# Here is where we're loading images into the page, four at a time, then go back up for a newPage<br />
for x,y in zip(xpos,ypos):<br />
if imagecount < len(D):<br />
f = scribus.createImage(x, y, pwidth, pheight)<br />
scribus.loadImage(imagedir + '/' + D[imagecount], f)<br />
scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=f)<br />
lenfilename = len(D[imagecount])<br />
Lpiclen = int(5.3 * lenfilename)<br />
# Lpic is the label for each picture, with position and length adjusted<br />
# according to the text length, so if you change the font or its size,<br />
# you may need to adjust this only approximate calculation.<br />
Lpic = scribus.createText(x, y + 193, Lpiclen, 15)<br />
scribus.setText(D[imagecount], Lpic)<br />
scribus.setTextAlignment(scribus.ALIGN_RIGHT, Lpic)<br />
scribus.setFont(labelFont, Lpic)<br />
scribus.setFontSize(8, Lpic)<br />
scribus.setFillColor("White", Lpic)<br />
imagecount += 1<br />
<br />
scribus.setRedraw(1)<br />
scribus.redrawAll()<br />
<br />
else:<br />
result = scribus.messageBox ('Not Found','No Images found with\n this search selection',scribus.BUTTON_OK)<br />
</pre><br />
<br />
==scribalbum_a4.py==<br />
<br />
This is the version that puts 8 images on A4 paper, with little extra space. Usage is as above.<br />
<br />
<pre><br />
<nowiki><br />
#!/usr/bin/env python<br />
<br />
# File: scribalbum_a4.py<br />
# originally 2005.02.13 Gregory Pittman<br />
# this version 2006.03.17 does without Tkinter<br />
# Uses valueDialog() for data entry of directory name<br />
# and also mnemonics for image types, j=jpg, and so on.<br />
# Also searches for uppercase equivalents.<br />
# Makes a new document<br />
<br />
from scribus import *<br />
import os<br />
<br />
filetype = []<br />
dicttype = {'j':'.jpg','p':'.png','t':'.tif','g':'.gif','P':'.pdf','J':'.jpeg'}<br />
Dicttype = {'j':'.JPG','p':'.PNG','t':'.TIF','g':'.GIF','P':'.PDF','J':'.JPEG'}<br />
<br />
imagedir = valueDialog('Images','Enter the Image Directory')<br />
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')<br />
for t in imagetype[0:]:<br />
filetype.append(dicttype[t])<br />
filetype.append(Dicttype[t])<br />
<br />
D=[]<br />
d = os.listdir(imagedir)<br />
for file in d:<br />
for format in filetype:<br />
if file.endswith(format):<br />
D.append(file)<br />
D.sort()<br />
labelFont = "DejaVu Sans"<br />
# There are 8 pictures per page; xpos and ypos are the x,y coord of the upper left corners<br />
xpos = (25, 321) <br />
ypos = (42, 236, 430, 624)<br />
# This proportion is right for photographs (at least for my digital Olympus)<br />
pwidth = 250<br />
pheight = 187<br />
imagecount = 0<br />
if len(D) > 0:<br />
if newDoc(PAPER_A4, (10,10,20,20),PORTRAIT, 1, UNIT_POINTS, NOFACINGPAGES, FIRSTPAGERIGHT):<br />
while imagecount < len(D):<br />
if imagecount > 0:<br />
newPage(-1)<br />
# L is the frame at the top of each page showing the directory name<br />
L = createText(15, 20, 200, 20)<br />
setText("Dir: " + imagedir, L)<br />
setTextAlignment(ALIGN_LEFT, L)<br />
setFont(labelFont, L)<br />
setFontSize(10, L)<br />
# Here is where we're loading images into the page, eight at a time, then go back up for a newPage<br />
for yframe in ypos:<br />
for xframe in xpos:<br />
if imagecount < len(D):<br />
f = createImage(xframe, yframe, pwidth, pheight)<br />
loadImage(imagedir + '/' + D[imagecount], f)<br />
setScaleImageToFrame(scaletoframe=1, proportional=1, name=f)<br />
lenfilename = len(D[imagecount])<br />
Lpiclen = int(5.3 * lenfilename)<br />
# Lpic is the label for each picture, with position and length adjusted according to the text length<br />
# so if you change in font or its size, you may need to adjust this only approximate calculation<br />
Lpic = createText(xframe + (250 - Lpiclen), yframe + 172, Lpiclen, 15)<br />
setText(D[imagecount], Lpic)<br />
setTextAlignment(ALIGN_RIGHT, Lpic)<br />
setFont(labelFont, Lpic)<br />
setFontSize(8, Lpic)<br />
setFillColor("White", Lpic)<br />
imagecount = imagecount + 1<br />
<br />
setRedraw(1)<br />
redrawAll()<br />
<br />
else:<br />
result = messageBox ('Not Found','No Images found with\n this search selection',BUTTON_OK)<br />
<br />
</nowiki><br />
</pre><br />
<br />
== album_letter_2.py ==<br />
<br />
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.<br />
<br />
<pre><nowiki><br />
#!/usr/bin/env python<br />
<br />
"""<br />
This is scribalbum_letter.py. This script will load the images from a<br />
directory, creating a new document of US Letter size.<br />
<br />
USAGE: It is probably better not to already have any document in Scribus,<br />
since memory usage can become intense when a large number of images is<br />
used.<br />
<br />
You are first presented with a dialog to choose either 4 or 6 images per page.<br />
Next select a directory where your images are located. Finally, select the <br />
types of image files, using the code you see in the last dialog. <br />
NOTE: If you choose PDF, only the first page will be imported, and the PDF <br />
will be rasterized.<br />
<br />
AUTHOR: Gregory Pittman Original version: 2005.02.13, this version: 2008.07.23<br />
<br />
LICENSE: This program is free software; you can redistribute it and/or modify <br />
it under the terms of the GNU General Public License as published by the Free <br />
Software Foundation; either version 2 of the License, or (at your option) any <br />
later version.<br />
<br />
http://wiki.scribus.net/index.php/Automatic_import_of_images:_Versions_not_requiring_Tkinter<br />
<br />
========================================================================<br />
<br />
Modifications by Henry Hartley - September, 2009:<br />
<br />
* allow user to specify 4, 6, or 12 images per page, selected at run time<br />
* changed font to Garamond Regular but provide a dialog for the user to change this at run time<br />
* Image are arranged in one of these ways:<br />
<br />
1 2 1 2 1 2 3<br />
3 4 3 4 4 5 6<br />
5 6 7 8 9<br />
10 11 12<br />
<br />
* figure out if images are landscape or portrait and adjust frame accordingly<br />
* center labels under images<br />
* offset page somewhat for 3-hole punch when printed double sided<br />
* replaced dir at top of all pages to a title, specified at run time<br />
* added page numbers (alternating corners for double sided printing)<br />
* the Scribus progress indicator and status line show how many files have<br />
been imported<br />
<br />
Note: 8.5 by 11 inch page is 612 by 792 points<br />
<br />
If you convert all images to a size close to what is needed by this script <br />
before running it then the memory requirements are reduced. The goal is to<br />
get an image that is the same size or only slightly larger than the image <br />
frame at 300dpi. Depending upon the number of pictures per page, this will <br />
be one of the following sizes:<br />
<br />
4 per page: 758 by 1137 pixels (182 by 273 points at 300dpi)<br />
6 per page: 608 by 912 pixels (146 by 219 points at 300dpi)<br />
12 per page: 421 by 633 pixels (101 by 152 points at 300dpi)<br />
<br />
One way to do this is to create a sub-directory under your image directory <br />
called "small" and then running a perl one-liner as shown below (assuming <br />
both Perl and ImageMagick are installed, of course).<br />
<br />
Note that the double backslash after "small" is required on MS Windows.<br />
Replace with a forward slash on Linux. The 37% used here works just about <br />
right when resizing images starting life as the 2048 by 3072 pixel images <br />
produced by my EOS D10 camera. Adjust accordingly. Fractional percentages <br />
are allowed.<br />
<br />
perl -e "((print qq|$_\n|) && system(qq|convert -resample 300 $_ -resize 50% small\\$_|)) foreach (glob(qq|*.jpg|))"<br />
<br />
"""<br />
<br />
import scribus<br />
import os<br />
<br />
filetype = []<br />
dicttype = {'j':'.jpg','p':'.png','t':'.tif','g':'.gif','P':'.pdf'}<br />
Dicttype = {'j':'.JPG','p':'.PNG','t':'.TIF','g':'.GIF','P':'.PDF'}<br />
nrimages = '0'<br />
<br />
while (nrimages != '4') and (nrimages != '6') and (nrimages != '12') and (nrimages != 'c'):<br />
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')<br />
<br />
imagedir = scribus.fileDialog('Select Image Directory','Directories',isdir=True)<br />
<br />
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')<br />
<br />
gallerytitle = scribus.valueDialog('Gallery Title','Enter the title you want to appear on all pages','')<br />
<br />
labelFont = scribus.valueDialog('Font for Text','Enter the name of the font you would like to use throughout your document','Garamond Regular')<br />
<br />
for t in imagetype[0:]:<br />
filetype.append(dicttype[t])<br />
filetype.append(Dicttype[t])<br />
d = os.listdir(imagedir)<br />
D = []<br />
for file in d:<br />
for format in filetype:<br />
if file.endswith(format):<br />
D.append(file)<br />
D.sort()<br />
<br />
# All of these numbers can be adjusted but what is here seems to work pretty well<br />
# If you would like to add new a new page size or layout, add a new set of values<br />
# in this section rather than replacing an existing set.<br />
<br />
if nrimages == '4':<br />
marginX = 24<br />
marginY = 24<br />
<br />
# Image height and width<br />
iHorW = 273<br />
iVerW = 182<br />
iVerH = iHorW<br />
iHorH = iVerW<br />
<br />
# Gap sizes and page offsets<br />
gapW = 6<br />
gapH = 73<br />
xOffset = 12<br />
yOffset = 58<br />
<br />
# Page title text frame<br />
titleFS = 18<br />
titleX = marginX<br />
titleY = marginY<br />
titleW = iHorW + iHorW + gapW<br />
titleH = titleFS * 2<br />
<br />
# Image label text frame<br />
# Height is enough to allow a second line of text if desired.<br />
labelGap = 6<br />
labelFS = 12<br />
labelH = labelFS * 3<br />
<br />
# Page number text frame<br />
pNumFS = 12<br />
pNumY = 759<br />
pNumXt = 1<br />
pNumW = 18<br />
pNumH = pNumFS * 1.5<br />
<br />
H2V = int((iHorW-iHorH)/2)<br />
V2H = int((iVerH-iVerW)/2)<br />
<br />
xPosH = [marginX, marginX + iHorW + gapW, marginX, marginX + iHorW + gapW]<br />
yPosH = [marginY + yOffset + V2H, marginY + yOffset + V2H, marginY + yOffset + iVerH + gapH + V2H, marginY + yOffset + iVerH + gapH + V2H]<br />
xPosV = [marginX + H2V, marginX + iHorW + gapW + H2V, marginX + H2V, marginX + iHorW + gapW + H2V]<br />
yPosV = [marginY + yOffset, marginY + yOffset, marginY + yOffset + iVerH + gapH, marginY + yOffset + iVerH + gapH]<br />
imgID = [0, 1, 2, 3]<br />
imgRow = 2<br />
<br />
<br />
<br />
if nrimages == '6':<br />
marginX = 48<br />
marginY = 18<br />
<br />
# Image height and width<br />
iHorW = 219<br />
iVerW = 146<br />
iVerH = iHorW<br />
iHorH = iVerW<br />
<br />
# Gap sizes and page offsets<br />
gapW = 30<br />
gapH = 18<br />
xOffset = 48<br />
yOffset = 24<br />
<br />
# Page title text frame<br />
titleFS = 12<br />
titleX = marginX<br />
titleY = marginY<br />
titleW = iHorW + gapW + iHorW<br />
titleH = titleFS * 2<br />
<br />
# Image label text frame<br />
# Height is enough to allow a second line of text if desired.<br />
labelGap = 0<br />
labelFS = 7<br />
labelH = labelFS * 3<br />
<br />
# Page number text frame<br />
pNumFS = 8<br />
pNumY = 759<br />
pNumXt = 1<br />
pNumW = 18<br />
pNumH = pNumFS * 1.5<br />
<br />
H2V = int((iHorW-iHorH)/2)<br />
V2H = int((iVerH-iVerW)/2)<br />
<br />
# It's quite likely that these longs lists could be replaced by a formula.<br />
# If anyone has the time to do that, it would probably make this script easier<br />
# to maintain.<br />
xPosH = [marginX, marginX + iHorW + gapW, marginX, marginX + iHorW + gapW, marginX, marginX + iHorW + gapW]<br />
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]<br />
xPosV = [marginX + H2V, marginX + iHorW + gapW + H2V, marginX + H2V, marginX + iHorW + gapW + H2V, marginX + H2V, marginX + iHorW + gapW + H2V]<br />
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)]<br />
imgID = [0, 1, 2, 3, 4, 5]<br />
imgRow = 2<br />
<br />
<br />
<br />
if nrimages == '12':<br />
marginX = 36<br />
marginY = 36<br />
<br />
# Image height and width<br />
iHorW = 152<br />
iVerW = 101<br />
iVerH = iHorW<br />
iHorH = iVerW<br />
<br />
# Gap sizes and page offsets<br />
gapW = 24<br />
gapH = 21<br />
xOffset = 36<br />
yOffset = 24<br />
<br />
# Page title text frame<br />
titleFS = 12<br />
titleX = marginX<br />
titleY = marginY<br />
titleW = iHorW + iHorW + gapW + iHorW + gapW<br />
titleH = titleFS * 2<br />
<br />
# Image label text frame<br />
# Height is enough to allow a second line of text if desired.<br />
labelGap = 0<br />
labelFS = 7<br />
labelH = labelFS * 3<br />
<br />
# Page number text frame<br />
pNumFS = 8<br />
pNumY = 759<br />
pNumXt = 2<br />
pNumW = 18<br />
pNumH = pNumFS * 1.5<br />
<br />
H2V = int((iHorW-iHorH)/2)<br />
V2H = int((iVerH-iVerW)/2)<br />
<br />
# It's quite likely that these longs lists could be replaced by a formula.<br />
# If anyone has the time to do that, it would probably make this script easier<br />
# to maintain.<br />
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)]<br />
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]<br />
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]<br />
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)]<br />
imgID = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]<br />
imgRow = 3<br />
<br />
<br />
# EXTRA CATEGORY - By putting this in I have a place to put temporary numbers <br />
# for one of a kind collections. For instance, the parameters above assume that<br />
# images will have the 3:2 aspect ratio of 35mm film or most digital camera <br />
# images. The numbers used here are slightly modified to work with images scanned <br />
# from 4x5 inch negatives.<br />
<br />
if nrimages == 'c':<br />
marginX = 36<br />
marginY = 48<br />
<br />
# Image height and width<br />
iHorW = 125<br />
iVerW = 100<br />
iVerH = iHorW<br />
iHorH = iVerW<br />
<br />
# Gap sizes and page offsets<br />
gapW = 60<br />
gapH = 45<br />
xOffset = 39<br />
yOffset = 36<br />
<br />
# Page title text frame<br />
titleFS = 12<br />
titleX = marginX<br />
titleY = marginY<br />
titleW = iHorW + iHorW + gapW + iHorW + gapW<br />
titleH = titleFS * 2<br />
<br />
# Image label text frame<br />
# Height is enough to allow a second line of text if desired.<br />
labelGap = 0<br />
labelFS = 7<br />
labelH = labelFS * 3<br />
<br />
# Page number text frame<br />
pNumFS = 8<br />
pNumY = 759<br />
pNumXt = 2<br />
pNumW = 18<br />
pNumH = pNumFS * 1.5<br />
<br />
H2V = int((iHorW-iHorH)/2)<br />
V2H = int((iVerH-iVerW)/2)<br />
<br />
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)]<br />
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]<br />
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]<br />
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)]<br />
imgID = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]<br />
imgRow = 3<br />
<br />
imageCount = 0<br />
pageNumber = 1<br />
scribus.progressTotal(len(D))<br />
if len(D) > 0:<br />
if scribus.newDoc(scribus.PAPER_LETTER, (marginX, marginX, marginY, marginY),scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.NOFACINGPAGES, scribus.FIRSTPAGERIGHT):<br />
while imageCount < len(D):<br />
if imageCount > 0:<br />
scribus.newPage(-1)<br />
<br />
# Here is where we're loading images into the page, four, six, or twelve at a time, then go back up for a newPage<br />
if pageNumber % 2 == 0:<br />
pOffset = 0<br />
pNumX = xPosH[0]<br />
else:<br />
pOffset = xOffset<br />
pNumX = xPosH[pNumXt] + iHorW + pOffset - pNumW<br />
<br />
# L is the frame at the top of each page showing the gallery title (read in above)<br />
L = scribus.createText(titleX + pOffset, titleY, titleW, titleH)<br />
scribus.setText(gallerytitle, L)<br />
scribus.setTextAlignment(scribus.ALIGN_CENTERED, L)<br />
scribus.setFont(labelFont, L)<br />
scribus.setFontSize(titleFS, L)<br />
<br />
for i in imgID:<br />
if imageCount < len(D):<br />
<br />
scribus.statusMessage("Placing image " + D[imageCount] + " in document (" + `imageCount` + " of " + `len(D)` + ")")<br />
scribus.progressSet(imageCount)<br />
<br />
# Create a temporary image object. Size and location are irrelivant<br />
tempImage = scribus.createImage(10, 10, 10, 10)<br />
<br />
# Populate that object with your image<br />
scribus.loadImage(imagedir + '/' + D[imageCount], tempImage)<br />
<br />
# Scale the image but NOT proportionally<br />
scribus.setScaleImageToFrame(scaletoframe=1, proportional=0, name=tempImage)<br />
<br />
# Use getImageScale to get the relative scaling in the x and y directions<br />
imgx,imgy = scribus.getImageScale(tempImage)<br />
<br />
# If imgx < imgy, you have an horizontal image, otherwise, <br />
# a vertical (or square) image. <br />
if imgx < imgy:<br />
x = xPosH[i] + pOffset<br />
y = yPosH[i]<br />
pWidth = iHorW<br />
pHeight = iHorH<br />
else:<br />
x = xPosV[i] + pOffset<br />
y = yPosV[i]<br />
pWidth = iVerW<br />
pHeight = iVerH<br />
<br />
# Can't have these cluttering up the page<br />
scribus.deleteObject(tempImage)<br />
<br />
# Now we create the REAL image object placed appropriately<br />
f = scribus.createImage(x, y, pWidth, pHeight)<br />
<br />
# and load the image<br />
scribus.loadImage(imagedir + '/' + D[imageCount], f)<br />
<br />
# this time when we scale the image, we do it proportionally<br />
scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=f)<br />
<br />
# Lpic is the label for each picture, the position is the same for all <br />
# image orientations and the labels are centered under the pictures.<br />
<br />
# Create the text frame.<br />
Lpic = scribus.createText(xPosH[i] + pOffset, yPosV[i] + iVerH + labelGap, iHorW, labelH)<br />
<br />
# populate with the file name<br />
scribus.setText(D[imageCount], Lpic)<br />
<br />
# and format as desired<br />
scribus.setTextAlignment(scribus.ALIGN_CENTERED, Lpic)<br />
scribus.setFont(labelFont, Lpic)<br />
scribus.setFontSize(labelFS, Lpic)<br />
scribus.setFillColor("White", Lpic)<br />
<br />
# increment the image count<br />
imageCount += 1<br />
<br />
# Now the page number<br />
<br />
# Create a text frame<br />
pNum = scribus.createText(pNumX, pNumY, pNumW, pNumH)<br />
<br />
# Put the page number in it and format<br />
scribus.setText(`pageNumber`, pNum)<br />
if imageCount < len(D):<br />
scribus.setTextAlignment(scribus.ALIGN_RIGHT, pNum)<br />
else:<br />
scribus.setTextAlignment(scribus.ALIGN_LEFT, pNum)<br />
scribus.setFont(labelFont, pNum)<br />
scribus.setFontSize(pNumFS, pNum)<br />
scribus.setFillColor("White", pNum)<br />
<br />
# Finally, we increment the page number<br />
pageNumber += 1<br />
scribus.setRedraw(1)<br />
scribus.redrawAll()<br />
<br />
else:<br />
result = scribus.messageBox ('Not Found','No Images found with\n this search selection',scribus.BUTTON_OK)<br />
<br />
scribus.setRedraw(1)<br />
scribus.redrawAll()<br />
<br />
scribus.statusMessage("")<br />
scribus.progressReset()<br />
<br />
</nowiki></pre></div>Hhartley