You are not logged in.

#1 2013-03-30 19:20:19

feilen
Member
Registered: 2013-03-30
Posts: 1

Simple patch for makepkg: Optimize PNG/JPEG images losslessly

Hello there! I've written a (rather simple) patch for Makepkg that makes use of the tools jpegoptim and optipng, using more or less the same method that the current code for using UPX works.

These two utilities use a handful of methods for producing more efficiently optimized image files, while not losing or altering the image given by decompression.

47c47
< packaging_options=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge' 'upx')
---
> packaging_options=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge' 'upx' 'img')
1055c1055
<               find . -type f -perm -u+w 2>/dev/null | while read binary ; do
---
>               find . -type f -iname "*.png"  2>/dev/null | while read binary ; do
1061a1062,1075
>       if [[ $(check_option img) = "y" ]]; then
>               msg2 "$(gettext "Compressing images...")"
>               local image
>               find . -type f 2>/dev/null | while read image ; do
>                       if [[ $(file -bi "$image") = *'image/png'* ]]; then
>                               optipng "$image" &>/dev/null ||
>                                               warning "$(gettext "Could not compress image : %s")" "${image/$pkgdir\//}"
>                       fi
>                       if [[ $(file -bi "$image") = *'image/jpeg'* ]]; then
>                               jpegoptim "$image" &>/dev/null ||
>                                               warning "$(gettext "Could not compress image : %s")" "${image/$pkgdir\//}"
>                       fi
>               done
>       fi
1647a1662,1669
>                       ret=1
>               fi
>       fi
>
>       # img - image compression
>       if [[ $(check_option img) == 'y' ]]; then
>               if ! type -p jpegoptim >/dev/null; then
>                       error "$(gettext "Cannot find the %s binary required for compressing images.")" "jpegoptim"

Save as makepkg.patch, patch /usr/bin/makepkg makepkg.patch, then add 'img' to your OPTIONS in /etc/makepkg.conf.

On most files this gives a 5-10% space optimization, but with smaller files or files which were badly compressed in the first place it can get 30-50%.

Obviously some things could be more elegant, there's no method given here to pass options to either program, but implementing that would be trivial.

Anyone interested?

Offline

#2 2013-03-30 19:48:45

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,412

Re: Simple patch for makepkg: Optimize PNG/JPEG images losslessly

You should ask about this on the [pacman-dev] mailing list.  It is nice that you are sharing it here.  But if you really think this is a superior way of handling it, then submitting it upstream for review is probably the better thing to do.

Offline

Board footer

Powered by FluxBB