Skip to content

Instantly share code, notes, and snippets.

@frozenpandaman
Last active January 8, 2020 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frozenpandaman/410567cfea6220cb7b89b12182352f75 to your computer and use it in GitHub Desktop.
Save frozenpandaman/410567cfea6220cb7b89b12182352f75 to your computer and use it in GitHub Desktop.
export psds of manga pages to png (save as indexed png ->remove exif tags -> pngcrush if worth it)
#!/bin/bash
dir="_png"
mkdir -p $dir # make diretory
for filename in *.psd; do # for all .psd files, save as indexed color .png, no transparency
if [[ "$filename" == *"-c"* ]]; then # grayscale unless "-c" (i.e. -credits, -color) in filename
cs="RGB"
else
cs="LinearGray"
fi
convert "$filename"[0] -colorspace $cs -colors 256 -background white -alpha remove -alpha off PNG8:$dir/"${filename%%.*}".png
done
exiftool -all= $dir/*.png # strip all exif data
rm $dir/*_original # clean up
for filename in $dir/*.png; do # pngcrush (compress) all files...
pngcrush "$filename" "${filename%%.*}.png.crush"
I=`stat -f "%z" "$filename"`
J=`stat -f "%z" "${filename%%.*}.png.crush"`
if [ $I -ge $J ]; then # ...unless resultant file isn't actually smaller
mv "${filename%.png}.png.crush" "$filename"
else
rm "${filename%%.*}.png.crush"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment