Last active
January 15, 2021 12:46
-
-
Save simonthompson99/d8bb8505f4ddd91d8fcd31fb5e683573 to your computer and use it in GitHub Desktop.
[Collapse png tree] Convert folder of pngs to a pdf taking folder name as filename #bash #imagemagick #file_operations
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
# Takes a folder tree of pngs and converts them to pdf per folder. e.g. | |
# |- 1 | |
# | |- 1_1.png | |
# | |- 1-2.png | |
# |- 2 | |
# | |- 2_1.png | |
# | |- 2_2.png | |
# | |
# will create two pdfs called 1.pdf and 2.pdf in the directory of script. | |
for file in `find . -name "*.png" -exec dirname {} \; | sort | uniq` | |
do | |
base="$(basename $file)" | |
echo "$base" | |
files="$(find $file -type f -name "*.png" | sort)" | |
echo "$files" | |
convert $files "$base.pdf" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment