From ee81bf80436212ad31579a136e4b15217880f9aa Mon Sep 17 00:00:00 2001 From: Doug Felt Date: Wed, 12 Apr 2017 08:53:18 -0700 Subject: [PATCH] Fix resize of grayscale images. When imagemagick 6.7.7-10 is processing the '-extent' operator and discovers an image is grayscale, it turns the 32-bit truecolor sRGB image into a grayscale image, but does so incorrectly-- the gray levels and alpha are wrong. Get around this by using composition to copy the source image over a slightly larger transparent image. --- Makefile | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f5811672a..f7a166d2e 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,7 @@ LDFLAGS = -lm `pkg-config --libs cairo` PNGQUANTDIR := third_party/pngquant PNGQUANT := $(PNGQUANTDIR)/pngquant PNGQUANTFLAGS = --speed 1 --skip-if-larger --force +IMOPS = -size 136x128 canvas:none -compose copy -gravity center # zopflipng is better (about 5-10%) but much slower. it will be used if # present. pass ZOPFLIPNG= as an arg to make to use optipng instead. @@ -150,15 +151,24 @@ $(PNGQUANT): waveflag: waveflag.c $(CC) $< -o $@ $(CFLAGS) $(LDFLAGS) + +# imagemagick's -extent operator munges the grayscale images in such a fashion +# that while it can display them correctly using libpng12, chrome and gimp using +# both libpng12 and libpng16 display the wrong gray levels. +# +# @convert "$<" -gravity center -background none -extent 136x128 "$@" +# +# We can get around the conversion to a gray colorspace in the version of +# imagemagick packaged with ubuntu trusty (6.7.7-10) by using -composite. + $(EMOJI_DIR)/%.png: $(EMOJI_SRC_DIR)/%.png | $(EMOJI_DIR) - @echo "emoji $< $@" - @convert -extent 136x128 -gravity center -background none "$<" "$@" + @convert $(IMOPS) "$<" -composite "PNG32:$@" $(FLAGS_DIR)/%.png: $(FLAGS_SRC_DIR)/%.png ./waveflag $(PNGQUANT) | $(FLAGS_DIR) @./waveflag $(FLAGS_DIR)/ "$<" $(RESIZED_FLAGS_DIR)/%.png: $(FLAGS_DIR)/%.png | $(RESIZED_FLAGS_DIR) - @convert -extent 136x128 -gravity center -background none "$<" "$@" + @convert $(IMOPS) "$<" -composite "PNG32:$@" flag-symlinks: $(RESIZED_FLAG_FILES) | $(RENAMED_FLAGS_DIR) @$(subst ^, , \