User:Wipp/Automatization
From Open Clip Art Library Wiki
Automatization
Suppose you want draw a lot of SVG's, each of them in two versions. For example you want coat of arms in a "flag" version and in a "coat of arms" version. You have put the flags in the directory "flags" and the coats of arm in the directory "coa". Now you want to publish all of them in plain svg with a thumbnail previewing both versions at once.
Here is a way to do that:
- Convert to plain svg:
inkscape <inkskape-svg> --export-plain-svg=<plain-svg>
- Do a check if the SVG contains links to something related to your home directory (in case you have forgot to delete a background image):
grep <username> *.svg
- Create thumbnails with heights of 200 px:
inkscape <inkscape-svg> --export-png=<thumbnail> -h 200
- Concatenate two thumbnails using ImageMagic:
montage -background none -geometry "1x1+0+0<" <thumb1> <thumb2> <final thumbnail>
Alltogether in Makefiles (GNU make under GNU/Linux):
Makefile:
SUBDIRS = flags coa
LAST_SUBDIR = $(lastword $(SUBDIRS))
PNG_DIR = png
FILE_BASES = $(notdir $(basename $(wildcard $(LAST_SUBDIR)/*.svg)))
PNGFILES = $(addsuffix .png,$(addprefix $(PNG_DIR)/,$(FILE_BASES)))
pngfiles: subdirs $(PNGFILES)
%.png : $(addsuffix /$(PNG_DIR)/%.png,$(addprefix ../,$(SUBDIRS)))
montage -background none -geometry "1x1+0+0<" $^ $@
.PHONY: subdirs $(SUBDIRS)
subdirs: $(SUBDIRS)
$(SUBDIRS):
$(MAKE) -f ../make.mk -C $@
make.mk:
PLAIN_SVG_DIR = plain-svg
USR = $(notdir $(wildcard ~))
PNG_DIR = png
PNG_HEIGHT = 200
SVG_FILES = $(wildcard *.svg)
PLAIN_SVG_FILES = $(addprefix $(PLAIN_SVG_DIR)/,$(SVG_FILES))
PNG_FILES = $(addsuffix .png,$(addprefix $(PNG_DIR)/,$(basename $(SVG_FILES))))
.DEFAULT_GOAL: all
all: plain png check
plain: $(PLAIN_SVG_FILES)
png: $(PNG_FILES)
check:
! grep $(USR) $(PLAIN_SVG_DIR)/*.svg
%.svg : ../%.svg
inkscape $< --export-plain-svg=$@
%.png : ../%.svg
inkscape -f $< --export-png=$@ -h $(PNG_HEIGHT)
The makefiles aren't very readable but they are very general. Suggestions for improvements are welcome!
Create a folder containing a directory structure like this:
- png
- coa
- png
- plain-svg
- flags
- png
- plain-svg
and put the makefiles in it. Then "make" will automatically create or update
- plain svg files for each svg in "coa" and "flags" in the appropriate "plain-svg"-subfolder
- png thumbnails for each svg in "coa" and "flags" in the appropriate "png"-subfolder
- A double thumbnail for each pair of files of the same name in "coa/png" and "flags/png" in the "png" folder
As an additional check, if a line containing your username is found in some of the plain svg files, make will complain.

