Skip to content

Instantly share code, notes, and snippets.

@cablespaghetti
Created June 5, 2020 14:41
Show Gist options
  • Save cablespaghetti/71d7db846b0b074f19bbef8c6561f845 to your computer and use it in GitHub Desktop.
Save cablespaghetti/71d7db846b0b074f19bbef8c6561f845 to your computer and use it in GitHub Desktop.
Resize and recompress pngs
#!/bin/bash
for image in *.png
do
width=$(identify -format '%w' $image)
height=$(identify -format '%h' $image)
cp $image $image.original
if [ $width -gt 350 ]
then
echo "$image - width: $width height: $height"
# Resize to 350px width keeping aspect ratio
convert $image -verbose -resize 350 $image
fi
# Recompress all images without losing much quality stripping metadata
pngquant --strip -f --ext .png --quality 70-95 $image
if [ $? -eq 99 ]
then
echo "pngquant skipped $image"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment