Last active
June 2, 2021 07:45
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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