Skip to content

Instantly share code, notes, and snippets.

@ranisalt
Created April 4, 2018 02:57
Show Gist options
  • Save ranisalt/fa385c8cda697852817fa74c5231b06a to your computer and use it in GitHub Desktop.
Save ranisalt/fa385c8cda697852817fa74c5231b06a to your computer and use it in GitHub Desktop.
Apply jpegoptim on makepkg (similar to optipng)
#!/usr/bin/bash
#
# jpegoptim.sh - Compress JPG files using jpegoptim
#
# Copyright (c) 2015-2016 Pacman Development Team <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
[[ -n "$LIBMAKEPKG_TIDY_JPEGOPTIM_SH" ]] && return
LIBMAKEPKG_TIDY_JPEGOPTIM_SH=1
LIBRARY=${LIBRARY:-'/usr/share/makepkg'}
source "$LIBRARY/util/message.sh"
source "$LIBRARY/util/option.sh"
packaging_options+=('jpegoptim')
tidy_modify+=('tidy_jpegoptim')
tidy_jpegoptim() {
if check_option "jpegoptim" "y"; then
msg2 "$(gettext "Optimizing JPEG images...")"
local jpeg
find . -type f -iname "*.jpeg" -o -iname "*.jpg" 2>/dev/null | while read -r jpeg ; do
if [[ $(file --brief --mime-type "$jpeg") = 'image/jpeg' ]]; then
jpegoptim "${JPEGOPTIMFLAGS[@]}" "$jpeg" &>/dev/null ||
warning "$(gettext "Could not optimize JPEG image : %s")" "${jpeg/$pkgdir\//}"
fi
done
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment