From ee81bf80436212ad31579a136e4b15217880f9aa Mon Sep 17 00:00:00 2001 From: Doug Felt Date: Wed, 12 Apr 2017 08:53:18 -0700 Subject: [PATCH 1/3] 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 ^, , \ From 2afcb05d169428d77743f6a4dac639286ad905e2 Mon Sep 17 00:00:00 2001 From: Doug Felt Date: Wed, 12 Apr 2017 08:59:16 -0700 Subject: [PATCH 2/3] Quiet makefile output. --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index f7a166d2e..fd48a0136 100644 --- a/Makefile +++ b/Makefile @@ -188,9 +188,9 @@ $(QUANTIZED_DIR)/%.png: $(EMOJI_DIR)/%.png $(PNGQUANT) | $(QUANTIZED_DIR) $(COMPRESSED_DIR)/%.png: $(QUANTIZED_DIR)/%.png | check_compress_tool $(COMPRESSED_DIR) ifdef MISSING_ZOPFLI - $(OPTIPNG) -quiet -o7 -clobber -force -out "$@" "$<" + @$(OPTIPNG) -quiet -o7 -clobber -force -out "$@" "$<" else - $(ZOPFLIPNG) -y "$<" "$@" 1> /dev/null 2>&1 + @$(ZOPFLIPNG) -y "$<" "$@" 1> /dev/null 2>&1 endif @@ -214,9 +214,9 @@ $(EMOJI).ttf: $(EMOJI).tmpl.ttf $(EMOJI_BUILDER) $(PUA_ADDER) \ $(ALL_COMPRESSED_FILES) | check_vs_adder @python $(EMOJI_BUILDER) -V $< "$@" "$(COMPRESSED_DIR)/emoji_u" @python $(PUA_ADDER) "$@" "$@-with-pua" - $(VS_ADDER) -vs 2640 2642 2695 --dstdir '.' -o "$@-with-pua-varsel" "$@-with-pua" - mv "$@-with-pua-varsel" "$@" - rm "$@-with-pua" + @$(VS_ADDER) -vs 2640 2642 2695 --dstdir '.' -o "$@-with-pua-varsel" "$@-with-pua" + @mv "$@-with-pua-varsel" "$@" + @rm "$@-with-pua" clean: rm -f $(EMOJI).ttf $(EMOJI).tmpl.ttf $(EMOJI).tmpl.ttx From fe67fac2409b1610acd907c8bb82f7572b747257 Mon Sep 17 00:00:00 2001 From: Doug Felt Date: Wed, 12 Apr 2017 09:00:01 -0700 Subject: [PATCH 3/3] Use quality param with optipng. When images are not processed due to not being able to meet the minimum quality setting, error 99 is returned, so catch this too so we still copy the file. Might still want to tweak these settings. --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index fd48a0136..9b21a0fe6 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ CFLAGS = -std=c99 -Wall -Wextra `pkg-config --cflags --libs cairo` LDFLAGS = -lm `pkg-config --libs cairo` PNGQUANTDIR := third_party/pngquant PNGQUANT := $(PNGQUANTDIR)/pngquant -PNGQUANTFLAGS = --speed 1 --skip-if-larger --force +PNGQUANTFLAGS = --speed 1 --skip-if-larger --quality 85-95 --force IMOPS = -size 136x128 canvas:none -compose copy -gravity center # zopflipng is better (about 5-10%) but much slower. it will be used if @@ -181,10 +181,10 @@ flag-symlinks: $(RESIZED_FLAG_FILES) | $(RENAMED_FLAGS_DIR) $(RENAMED_FLAG_FILES): | flag-symlinks $(QUANTIZED_DIR)/%.png: $(RENAMED_FLAGS_DIR)/%.png $(PNGQUANT) | $(QUANTIZED_DIR) - @($(PNGQUANT) $(PNGQUANTFLAGS) -o "$@" "$<"; case "$$?" in "98") cp $< $@;; *) exit "$$?";; esac) + @($(PNGQUANT) $(PNGQUANTFLAGS) -o "$@" "$<"; case "$$?" in "98"|"99") echo "reuse $<"; cp $< $@;; *) exit "$$?";; esac) $(QUANTIZED_DIR)/%.png: $(EMOJI_DIR)/%.png $(PNGQUANT) | $(QUANTIZED_DIR) - @($(PNGQUANT) $(PNGQUANTFLAGS) -o "$@" "$<"; case "$$?" in "98") cp $< $@;; *) exit "$$?";; esac) + @($(PNGQUANT) $(PNGQUANTFLAGS) -o "$@" "$<"; case "$$?" in "98"|"99") echo "reuse $<";cp $< $@;; *) exit "$$?";; esac) $(COMPRESSED_DIR)/%.png: $(QUANTIZED_DIR)/%.png | check_compress_tool $(COMPRESSED_DIR) ifdef MISSING_ZOPFLI