I am looking for advice on how to automate the creation of a series of images. Basically, I have some simple shapes that are each their own svg file, and I have a bunch of well defined rules for how I want to combine them. The problem is very similar to combining the four suites of a deck of cards (one image for the heart, one for the spade, etc) into the 52 cards of the deck, using some mapping that gives the coordinates of each image on each card.
If I were doing this manually, I'd import the svg of the appropriate suite, scale it to the right size, maybe rotate it, position it where on the card it needs to be, and repeat however many number of times it takes to get the necessary number on the card. Obviously this becomes tedious after about the second card, and given that I can define in advance the positioning in every image (there's no by-eye placement), it seems amenable to automating.
I've tried looking into scripting with inkscape, but the only posts I've found only mention it in terms of "this could be scripted but I don't know how".
I thought I might be able to use the command line with verbs, but since AFAIK verbs don't take arguments, I don't know how I'd be able to adjust scale, position, etc.
Writing an extension seems like it's coming at it from the wrong direction and quite a bit of overkill, although being able to write this in python would be great.
It may even be that inkscape is the wrong tool for the job. But it seems to have potential; I've looked into manipulating svg images through python in other ways, but everything I've found is too low-level (e.g., I can draw lines and rectangles, but not import, scale, and position an existing svg)
Any suggestions on what sort of approach I could take to do this?
Advice to batch generate images by combining other SVGs
Re: Advice to batch generate images by combining other SVGs
Hah! Well, I'm one of those who would say, yes, this seems do-able, but I don't know how!
I would suggest posting on the Inkscape User mailing list. https://inkscape.org/en/community/mailing-lists/ Many, if not most developers (people who know SVG/XML very, very well, and also know how to write scripts and codes) will see it there, as well as advanced Inkscape users who don't participate in forums. I can't predict whether you'll get a quick answer there, or any answer at all. But based on my observation of activity on that list, I'd say there's a good chance you'll get some excellent advice
I would suggest posting on the Inkscape User mailing list. https://inkscape.org/en/community/mailing-lists/ Many, if not most developers (people who know SVG/XML very, very well, and also know how to write scripts and codes) will see it there, as well as advanced Inkscape users who don't participate in forums. I can't predict whether you'll get a quick answer there, or any answer at all. But based on my observation of activity on that list, I'd say there's a good chance you'll get some excellent advice

Basics - Help menu > Tutorials
Manual - Inkscape: Guide to a Vector Drawing Program
Inkscape Community - Inkscape FAQ - Gallery
Inkscape for Cutting Design
Manual - Inkscape: Guide to a Vector Drawing Program
Inkscape Community - Inkscape FAQ - Gallery
Inkscape for Cutting Design
Re: Advice to batch generate images by combining other SVGs
gpaciga wrote:but everything I've found is too low-level (e.g., I can draw lines and rectangles, but not import, scale, and position an existing svg)
It will help if you explain what are your rules
say you want to draw faces from a set of hair, eyes, nose and lips
pseudo code would be something like this
for each nose in noses
for each hair in hairs
for each lip in lips
for each eye in eyes
var svg = "
<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink= 'http://www.w3.org/1999/xlink'>
<image xlink:href='"+hair.name+"' x="0" y="0" width="300" height="80">
<image xlink:href='"+eye.name+"' x="0" y="200" width="300" height="80">
<image xlink:href='"+nose.name+"' x="0" y="250" width="300" height="80">
<image xlink:href='"+lip.name+"' x="0" y="400" width="300" height="80" transform="scale(0.8)">
</svg>
var name = hair.name+eye.name+nose.name+lip.name + ".svg"
File.save(name,svg)
}
}
}
}
You got :
import => xlink:href
scale => transform...
position => x,y
Re: Advice to batch generate images by combining other SVGs
I think sounds exactly like what I need. The variables in my deck of cards example would be suit and rank, rather than nose, hair, etc, but the solution looks pretty generic. Being able to compose the svg from those image elements means I can write a python script pretty easily to do what I need.
I won't be able to try putting this into practice probably until next week, but I'll report back with further questions/failures/successes once I do.
Code: Select all
image xlink:href
I won't be able to try putting this into practice probably until next week, but I'll report back with further questions/failures/successes once I do.