Saturday, 2 January 2021

ImageMagick Crop, Chop PNG and make a PDF

 


Scripts to chop, resize PNG file using ImageMagick (Convert)

001_multi_convert_text.sh

#Submit first
./002_cropImage.sh "" &

#Submit rest 
for x in {1..40}
do
y=$((x+1))
./002_cropImage.sh $x &
done
exit 0


002_cropImage.sh

#!/bin/bash
to_replace="."
temp="_edited."

for a_file in $(ls -tr | grep -E ^$1[0-9]\{1\}\.png)
do
echo "Now doing input file - "$a_file" Output will be " ${a_file//$to_replace/$temp}
# convert $a_file -crop 1920x1080+1920+95 ${a_file//$to_replace/$temp}
# convert $a_file -crop 1000x1080+460+0 ${a_file//$to_replace/$temp}
# convert $a_file -crop 1000x1000+2400+95 ${a_file//$to_replace/$temp}
convert $a_file -gravity West -chop 470x0 -gravity East -chop 470x0 -gravity North -chop 0x20 -gravity South -chop 0x40 -resize 80% ${a_file//$to_replace/$temp}
done
exit 0


Command to merge the PNGs to a PDF

convert -quality 100 $(find -type f -name '*edited.png' | sort -V) output.pdf

No comments: