1

I wish to show my photo collection on my television. In order to do this, I need to resize the photos to fit in a 1920x1080px window (because the performance is awful when dealing with the originals).

My intended structure is:

/path/to/originalphotos/
/path/to/originalphotos/2016/2016-01-01 Description/DSC_1234.JPG
/path/to/originalphotos/2019/2019-12-31 Description/DSC_5678.JPG

/path/to/thumbnails/
/path/to/thumbnails/2016/2016-01-01 Description/DSC_1234_thumb.JPG
/path/to/thumbnails/2019/2019-12-31 Description/DSC_5678_thumb.JPG

I am trying to create a script that loops through /path/to/originalphotos/ and creates a thumbnail (using Imagemagick's convert utility) of every .JPG-file in the corresponding subdirectory.

So far, my Bash script looks like this:

#!/bin/bash
SOURCE_PATH="/path/to/originalphotos/"
DESTINATION_PATH="/path/to/thumbnails/"
find "$SOURCE_PATH" -type f -iname '*.jpg' -exec sh -c 'echo convert \"$1\" -auto-orient -resize 1920x1080\> --write \"$DESTINATION_PATH${0%}_thumb.JPG\"' -- {} \;

Note that I added echo to avoid saving any data.

Can you provide any help to store the thumbnails correctly?

I have a gut feeling that I will encounter issues later on as some of my folder names contain special Danish characters (Æ, Ø, Å).

1 Answer 1

1

I don't think your folder names will be an issue at all. But I would suggest using shell globbing instead of find, just to make the syntax simpler. Something like this:

shopt -s globstar nullglob 
destination=/path/to/thumbnails
cd /path/to/originalphotos
for i in **/*{jpg,JPG}; do 
    dirName=${i%/*}
    file=$(basename "$i")
    fileName="${file%.*}"
    echo convert "$i" -auto-orient -resize 1920x1080\> \
        --write "$destination/${fileName}_thumb.JPG" 
done

That will deal with both jpg and JPG files, but note that all thumbs will end up as .JPG, regardless of whether they were .jpg or .JPG originally. If that's a problem, you could do something like this instead:

for i in **/*{jpg,JPG}; do 
    dirName=${i%/*} 
    file=$(basename "$i")
    fileName="${file%.*}" 
    ext="${file##*.}" 
    echo convert "$i" -auto-orient -resize 1920x1080\> \
        --write "$destination/${fileName}_thumb.$ext"
done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .