Script to simplify icon export?

Asked by Olof Bjarnason

I draw icons daily. I have lots of icons in one drawing, to enable fast re-use of colors and objects.

To simplify export, I have a "bottom layer" which I call "fakepages". In that layer, I have rectangles of sizes 16x16, 24x24 and 32x32. One rectangle beneath each icon.

So when I want to export an icon:

1. I select the fake page rectangle beneath it
2. [Ctrl+Shift+D] bring up the Document window
3. [Alt+F] fit the page to selection
4. Close the window
5. [Ctrl+Alt+E] Export window
6. Browse to the right icon path for export
7. Press Export
8. Confirm the export

As you can imagine, this "algorithm" becomes quite a bore when I'm changing the color scheme of a whole series of icons, or changing icon sizes, or some other icon-set operation.

I know Python can be used to script things in Inkscape. Would it be possible to write a script, that somehow automates (parts of) this algorithm?

Question information

Language:
English Edit question
Status:
Solved
For:
Inkscape Edit question
Assignee:
No assignee Edit question
Solved by:
Olof Bjarnason
Solved:
Last query:
Last reply:
Revision history for this message
su_v (suv-lp) said :
#1

1) Use built-in feature of the 'Export Bitmap' dialog

a) 'Page resize' for bitmap exporting a selection is unneeded:
The 'Export Bitmap' dialog allows to export the current selection, optionally including all objects beneath (i.e. only what is visible within the bounding box of the current selection, like cropping if your selection is a rectangle in a 'slicing' layer on top.

b) Repeat for each icon after each round of changes manually
The 'Export Btmap' dialog allows batch exporting using export hints (path, file name, dpi) stored with each previously separately exported object - i.e. you have to manually export each icon-rectangle only once, later the path and file name of the first export will be reused when batch exporting all your icon-rectangles in one go.

About using the built-in support for slicing and batch-exporting to bitmap:
<http://tavmjong.free.fr/INKSCAPE/MANUAL/html/File-Export.html#id4337007>
<http://wiki.inkscape.org/wiki/index.php/Release_notes/0.46#Bitmap_export>

2) Alternatively have a look at the extension 'Inkscape-Slicer'
<http://github.com/mattharrison/Inkscape-Slicer-Extension> - it doesn't do batch exporting IIRC but it makes slicing the SVG file into PNG images easier.

Note: AFAICT both workflows just (well, almost ;-) ) require to move your current bottom layer 'fakepages' to the top and use the rectangles there as export slices (depending on which solution you choose with fill&stroke turned off or not).

Revision history for this message
Olof Bjarnason (objarni) said :
#2

Oh this is nice :) You made my day hehe.

I trying (1) with a couple of icons, I didn't have to move the layer to top (I'm using Inkscape 0.47, don't know that the logic of export selection has changed since 0.46).

Only that speeds things up a lot (since the fit-page-to-selection is the single slowest step in the "algorithm".)

Next thing: remembering the paths and getting batch-export working. That would be wonderful!

[The slicer extension looks marvellous too, but it would require lots of work for me to change my 100+ icons project to that "format". maybe for future projects. thanks for the link!]