Created
February 9, 2023 18:48
-
-
Save lincerely/1499d759f7a4c3f4f50c4aab85e4bfd0 to your computer and use it in GitHub Desktop.
unpack Autodesk Sketchbook multi-layered TIFF to 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
| #!/usr/bin/env bash | |
| # sketchbook_unpack.sh | |
| # unpack Autodesk Sketchbook multi-layered TIFF to PNGs | |
| # | |
| # requires: libtiff, imagemagick | |
| # reference: https://www.awaresystems.be/imaging/tiff/tifftags/docs/alias.html | |
| input="$1" | |
| test -f "$input" || (echo "usage: $0 TIFF_FILE" && exit 1) | |
| dir=`dirname "$input"` | |
| base=`basename "$input" .tiff` | |
| outdir="$input.dir" | |
| mkdir "$outdir" | |
| tiffinfo "$input" >"$input.info" 2>/dev/null | |
| cwidth=`grep 'Image Width' "$input.info" | sed 's/.*Width: \([0-9]*\).*/\1/'` | |
| cheight=`grep 'Image Length' "$input.info" | sed 's/.*Length: \([0-9]*\).*/\1/'` | |
| grep SubIFD "$input.info" | sed -e 's/^.*: //' -e 's/ /\n/g' |\ | |
| while read line; do | |
| output="$dir"/"$base"_"$line".tiff | |
| info="$dir"/"$base"_"$line".tmp | |
| tiffinfo -o $line "$input" > "$info" 2>/dev/null | |
| if ! grep -q 'reduced-resolution image (1 = 0x1)' "$info" ; then | |
| pos_x=`grep Position "$info" | sed 's/.*: \([0-9]*\).*/\1/'` | |
| pos_y=`grep Position "$info" | sed 's/.*, \([0-9]*\)$/\1/'` | |
| width=`grep 'Image Width' "$info" | sed 's/.*Width: \([0-9]*\).*/\1/'` | |
| height=`grep 'Image Length' "$info" | sed 's/.*Length: \([0-9]*\).*/\1/'` | |
| off_x=`expr 0$pos_x` | |
| off_y=`expr 0$cheight - 0$pos_y - 0$height` | |
| tiffcp -o $line "$input" "$output" 2>/dev/null | |
| magick "$output" \ | |
| -flip \ | |
| -separate -swap 0,2 -combine \ | |
| -set page "$cwidth"x"$cheight"+"$off_x"+"$off_y" \ | |
| -background none \ | |
| -flatten \ | |
| "$outdir/$base"_"$line.png" | |
| rm "$output" | |
| fi | |
| rm "$info" | |
| done | |
| rm "$input.info" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO: find a way to compose layers into a PSD, imagemagick produces corrupted psd with current outputed PNGs.