Skip to content

Instantly share code, notes, and snippets.

@martinec
Last active June 2, 2021 07:45
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinec/db31490cedf0cee753ca to your computer and use it in GitHub Desktop.
Save martinec/db31490cedf0cee753ca to your computer and use it in GitHub Desktop.
Batch convert a favicon.svg file in a favicon.ico image (different sizes)
# Batch convert a favicon.svg file in a favicon.ico image (different sizes)
# This makefile uses inkscape, convert, optipng and advpng command line tools
# type make favicon
# Cristian Martinez
all: icons
# Input SVG images without extensions
IMAGES = favicon
# Output PNG sizes
SIZES = 16 32 48 64 72 128
# Commands
INKSCAPE = inkscape
CONVERT = convert
OPTIPNG = optipng
ADVPNG = advpng
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)))
favicon: $(OUTPUTS)
$(CONVERT) $(OUTPUTS) favicon.ico
icons: $(OUTPUTS) .FORCE
%.png:
@echo "# creating $@"
@$(INKSCAPE) --export-png $@ -w $(lastword $(subst $(DASH),.svg ,$*)) \
$(firstword $(subst $(DASH),.svg ,$*))
@$(OPTIPNG) -quiet -o7 $@
@$(ADVPNG) -q -z -4 $@
# @$(CONVERT) $@ -border 0 -compress None $@
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