Skip to content

Instantly share code, notes, and snippets.

@iitenkida7
Last active February 2, 2020 04:24
Show Gist options
  • Save iitenkida7/23a3496827cbba07b42b69821f1830d8 to your computer and use it in GitHub Desktop.
Save iitenkida7/23a3496827cbba07b42b69821f1830d8 to your computer and use it in GitHub Desktop.
#!/bin/bash -eu
# mozjpeg 使って指定ディレクトリのjpeg ファイルを再帰的に 圧縮
# https://github.com/mozilla/mozjpeg
if [ ! -d $1 ] ;then
echo "該当ディレクトリが見当たりません" 1>&2
exit 1
fi
for IMAGE in $(find $1 -type f -name "*.jpg" -o -name "*.jpeg") ; do
echo -n "$(ls -lh "${IMAGE}" | awk '{print $9, "["$5}' ) => "
/opt/mozjpeg/bin/cjpeg -optimize -quality 70 "${IMAGE}" > "${IMAGE}_renew"
mv -f "${IMAGE}_renew" "${IMAGE}"
ls -lh "${IMAGE}" | awk '{print $5"]"}'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment