Le Tue 23 June 2015
As I alluded to in an earlier page on the Inkscape script, I am creating a story telling card game. In order to be focused on creating the content, I wanted to come up with some tools to take a text list and distribute it across a series of pages to make cards and then add a background image to each card. Doing this by hand with such a huge deck of cards is a bit of a chore, and so I developed some scripts to help me. One is for text, and this is described on this page, and the image one is described here. After playing around with Inkscape and the script I had developed for that I felt that Inkscape's single-page-per-file arrangement would be cumbersome and limiting so I decided to do it in Scribus, a publishing package that I came to appreciate when writing newsletters for the Wellington Potters Association. Scribus has python as its scripting language, and despite the documentation I could find being quite patchy, I was able to figure out how to get it to meet my needs successfully. So here is a script for laying out card sized images across multiple pages ready for text to be added over the top.
I have designed this script for business card size cards. They are 55mm x 90mm and an A4 landscape format page can hold ten of them if the margins are set at 11mm for the sides, and 15mm for the top and bottom. For different sized cards and spacing it is just a matter of changing the variables w and h to the desired size and altering the number in the x and y expressions to reflect the margins used. You will also need to adjust the number of cards to produce in the
NumImg variable. Maybe at a later stage I'll add these into some sort of UI, but for now this works sufficiently for the occasional project. The script also ensures the image goes to the back-most layer.
Although I have not included it in this edition of the script I see it as being a simple modification to the code to lay out a set of different cards on all even pages. This will allow front and back images on the cards if printed double sided.
In order to run the script from within Scribus you will need to start a new project with the page format described above and with enough pages in it to contain all of your cards. If you have already started a project and used the list to text box script you can just run this image layout script within that document file to apply the image as a background to all of the existing cards. Access the scripts through the Scripts>Execute Script menu item.
You can download the script from here: CardBackGroundImage-Loaderv0.py
#!/usr/bin/env python """ This script loads an image into a document and lays them out in a grid for printing a number of cards. They are set to be for business card sized cards. Each image is a seperate image object and spaced across a page appropriately. There are 10 cards to a page. You will need to ensure there are enough pages in your document to hold all of the cards you generate. @author: Hamish Trolove @website: www.techmonkeybusiness.com @version: CardBackGroundImage-Loaderv0.py @copyright Creative Commons - by nc sa """ import sys try: import scribus except ImportError: print "This script only runs from within Scribus." sys.exit(1) try: from PIL import Image except ImportError: print "Unable to import the Python Imaging Library module." sys.exit(1) ImgFileName = scribus.fileDialog("Find your background image file please", "*","" ,True, False) img = Image.open(ImgFileName) xsize, ysize = img.size #The image provided must be the correct proportions for the card. In this case 55mm x 90mm. The #image used is the same background for all cards. multTx = 0 # Multiplier for the column position multTy = 0 # Multiplier for the row position pageInd = 1 # Page number w = 55 #Width of Image frame h = 90 #Height of Image frame scribus.gotoPage(pageInd) # Make sure it always starts from first page NumImg = 52 #Number of images to insert. Change this as needed. for i in range(1,NumImg+1) : if multTy > 1: multTy = 0 multTx = 0 pageInd = pageInd + 1 scribus.gotoPage(pageInd) x = 11 + w * multTx #first corner is 11mm across. y = 15 + h * multTy #first corner is 15mm down. # create an image frame and put the image into it #The business card dimensions are known and so we are looking to drop image into this size frame. ImageFrame = scribus.createImage(x, y, w, h) scribus.loadImage(ImgFileName, ImageFrame) scribus.setScaleImageToFrame(True, False,ImageFrame) scribus.setFillColor("None", ImageFrame) scribus.setLineColor("None", ImageFrame) scribus.selectObject(ImageFrame) scribus.moveSelectionToBack() scribus.deselectAll() # Control to index around the page. if multTx > 3: multTy = multTy + 1 multTx = 0 x = 11 else: multTx = multTx + 1
A fun modification to this script can be found here: Python and Scribus Scripts to Deal Story Cards
This script takes the various story element cards and text and generates a random card spread to use for story generation inspiration.