Last active
October 13, 2022 10:23
-
-
Save innermond/d110d6234123bf87cc04 to your computer and use it in GitHub Desktop.
Extract images from pdf but, surprise! The images that contain alpha channels are extracted as two images. The source and the mask, as they are stored inside pdf file. This script recombine them into an one png file with given transparency
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/bash | |
# extract images from pdf at first-hand | |
#prefix=pict | |
#echo extract images from "$1" | |
#pdfimages -j "$1" $prefix | |
# IMAGES ARE SAVED SECVENTIALLY AS IMAGE AND THE NEXT IS A MASK IMAGE !!!! | |
declare -a files=($(ls *.ppm *.pbm)) | |
mask= | |
image= | |
for (( i = 0; i < ${#files[*]}; i = i + 2 )) | |
do | |
image=${files[$i]} | |
mask=${files[$i+1]} | |
echo converting "${image%.*}".png | |
convert $image $mask -compose CopyOpacity -composite "${image%.*}".png | |
echo removing image and it\'s mask | |
rm "$image" "$mask" | |
done | |
echo done! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment