Created
June 5, 2020 14:41
-
-
Save cablespaghetti/71d7db846b0b074f19bbef8c6561f845 to your computer and use it in GitHub Desktop.
Resize and recompress pngs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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