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.
pull/113/head
Doug Felt 2017-04-12 08:53:18 -07:00
parent ff93f20f66
commit ee81bf8043
1 changed files with 13 additions and 3 deletions

View File

@ -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 ^, , \