Last active
April 10, 2018 03:46
-
-
Save jkenlooper/1529699c7cf5bd2e66669d930461f673 to your computer and use it in GitHub Desktop.
Makefile for resizing jpgs that have a hint ratio in their name to multiple sizes.
This file contains 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
# Resizes jpgs that have a hint ratio in their name to multiple sizes. | |
# For example the cat-2-3.jpg will create resized jpgs: | |
# cat.280x420.jpg, cat.600x900.jpg, cat.1200x1800.jpg | |
unit_sizes := 140 300 600 | |
# Find all hinted jpgs in gallery/ that have the ratio hint suffix (-2-2.jpg) | |
hinted := $(shell find media/gallery -name '*-[0-9]-[0-9].jpg') | |
# Init with nothing and allow each RESIZE_TARGET_template to append to this var. | |
resized := | |
# clear out any suffixes | |
.SUFFIXES: | |
.SECONDEXPANSION: | |
.PHONY : all clean | |
all : $$(resized) | |
define RESIZE_TARGET_template | |
resized += $$(patsubst %-$(1).jpg,%.$(2).jpg,$$(filter %-$(1).jpg,$$(hinted))) | |
%.$(2).jpg : %-$(1).jpg | |
convert $$< -resize $(2) $$@ | |
endef | |
define UNIT_template | |
$$(eval $$(call RESIZE_TARGET_template,1-1,$$(strip $$(shell echo "1*$(1)" | bc))x$$(strip $$(shell echo "1*$(1)" | bc)))) | |
$$(eval $$(call RESIZE_TARGET_template,1-2,$$(strip $$(shell echo "1*$(1)" | bc))x$$(strip $$(shell echo "2*$(1)" | bc)))) | |
$$(eval $$(call RESIZE_TARGET_template,1-3,$$(strip $$(shell echo "1*$(1)" | bc))x$$(strip $$(shell echo "3*$(1)" | bc)))) | |
$$(eval $$(call RESIZE_TARGET_template,2-1,$$(strip $$(shell echo "2*$(1)" | bc))x$$(strip $$(shell echo "1*$(1)" | bc)))) | |
$$(eval $$(call RESIZE_TARGET_template,2-2,$$(strip $$(shell echo "2*$(1)" | bc))x$$(strip $$(shell echo "2*$(1)" | bc)))) | |
$$(eval $$(call RESIZE_TARGET_template,2-3,$$(strip $$(shell echo "2*$(1)" | bc))x$$(strip $$(shell echo "3*$(1)" | bc)))) | |
$$(eval $$(call RESIZE_TARGET_template,3-1,$$(strip $$(shell echo "3*$(1)" | bc))x$$(strip $$(shell echo "1*$(1)" | bc)))) | |
$$(eval $$(call RESIZE_TARGET_template,3-2,$$(strip $$(shell echo "3*$(1)" | bc))x$$(strip $$(shell echo "2*$(1)" | bc)))) | |
$$(eval $$(call RESIZE_TARGET_template,3-3,$$(strip $$(shell echo "3*$(1)" | bc))x$$(strip $$(shell echo "3*$(1)" | bc)))) | |
endef | |
$(foreach size,$(unit_sizes),$(eval $(call UNIT_template,$(size)))) | |
clean : | |
@echo "Removing resized files" | |
@echo $(resized) | xargs rm |
This file contains 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
3-2 | |
2-2 | |
1-2 | |
2-2 | |
1-2 | |
1-1 | |
1-1 | |
1-1 | |
3-1 | |
3-2 | |
2-2 | |
1-2 | |
2-3 | |
1-2 | |
1-1 | |
3-1 | |
3-2 | |
3-2 | |
3-2 | |
1-2 | |
1-2 | |
1-2 | |
2-2 | |
2-2 | |
2-2 | |
2-2 | |
1-2 | |
1-2 | |
1-2 | |
1-2 | |
3-3 | |
3-3 | |
1-1 | |
1-1 | |
1-1 | |
1-1 | |
1-1 | |
1-1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment