From 9917930ae1f02fdf85c1ca2a35ee039f1a17368f Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Mon, 26 Jan 2015 11:25:23 +0100 Subject: add option to optimize PNG images with optipng This can decrease package size by optimizing PNG image size. Images are just stored with better compression and/or filter options. The actual image content is not altered. Additionally this can automatically fix broken PNG images which caused some trouble lately. Signed-off-by: Christian Hesse Signed-off-by: Allan McRae --- scripts/makepkg.sh.in | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'scripts/makepkg.sh.in') diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 4640f033..40913c5e 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -49,7 +49,7 @@ declare -r startdir="$PWD" LIBRARY=${LIBRARY:-'@libmakepkgdir@'} packaging_options=('strip' 'docs' 'libtool' 'staticlibs' 'emptydirs' 'zipman' - 'purge' 'upx' 'debug') + 'purge' 'upx' 'optipng' 'debug') other_options=('ccache' 'distcc' 'buildflags' 'makeflags') splitpkg_overrides=('pkgdesc' 'arch' 'url' 'license' 'groups' 'depends' 'optdepends' 'provides' 'conflicts' 'replaces' 'backup' @@ -1918,6 +1918,17 @@ tidy_install() { fi done fi + + if check_option "optipng" "y"; then + msg2 "$(gettext "Optimizing PNG images...")" + local png + find . -type f -iname "*.png" 2>/dev/null | while read -r png ; do + if [[ $(file --brief --mime-type "$png") = 'image/png' ]]; then + optipng "${OPTIPNGFLAGS[@]}" "$png" &>/dev/null || + warning "$(gettext "Could not optimize PNG image : %s")" "${png/$pkgdir\//}" + fi + done + fi } find_libdepends() { @@ -3008,6 +3019,14 @@ check_software() { fi fi + # optipng - PNG image optimization + if check_option "optipng" "y"; then + if ! type -p optipng >/dev/null; then + error "$(gettext "Cannot find the %s binary required for optimizing PNG images.")" "optipng" + ret=1 + fi + fi + # distcc - compilation with distcc if check_buildenv "distcc" "y" && ! check_option "distcc" "n"; then if ! type -p distcc >/dev/null; then -- cgit v1.2.3-24-g4f1b