Skip to content

Instantly share code, notes, and snippets.

@martinec
Last active August 29, 2015 14:01
Show Gist options
  • Save martinec/3e739d139c1e87f2fa11 to your computer and use it in GitHub Desktop.
Save martinec/3e739d139c1e87f2fa11 to your computer and use it in GitHub Desktop.
Batch convert SVG files in a set of PNG images in different sizes
# This makefile uses the inkscape command line mode to export
# SVG files in a set of foo-{SIZES}.png images
all: icons
# Input SVG images without extensions
IMAGES = icon icon_inactive
# Output PNG sizes
SIZES = 16 32 48 64
INKSCAPE = inkscape
DASH = -
INPUTS := $(foreach icon, $(IMAGES), $(icon).svg)
OUTPUTS := $(patsubst %.svg, %, $(INPUTS))
SUFFIXES := $(foreach size, $(SIZES), $(DASH)$(size).png)
OUTPUTS := $(foreach img, $(OUTPUTS), $(addprefix $(img),$(SUFFIXES)))
icons: $(OUTPUTS) .FORCE
%.png:
@echo "# creating $@"
@$(INKSCAPE) --export-png $@ -w $(lastword $(subst $(DASH),.svg ,$*)) \
$(firstword $(subst $(DASH),.svg ,$*))
clean:
@rm -f $(OUTPUTS)
@echo "all files have been removed"
.FORCE:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment