linux - How should I batch make thumbnails with the original images located in multiple subdirectories? -
i have original images in directory structure looks this:
./alabama/1.jpg ./alabama/2.jpg ./alabama/3.jpg ./alaska/1.jpg ...the rest of states... i wanted convert of original images thumbnails can display them on website. after bit of digging / experimenting, came following linux command:
find . -type f -iname '*.jpg' | sed -e 's/\.jpg$//' | xargs -i y convert y.jpg -thumbnail x100\> y-small.jpg it recursively finds jpg images in subdirectories, removes file type (.jpg) them can rename them later, makes them thumbnail , renames them '-small' appended before file type.
it worked purposes, tad complicated , isn't robust. example, i'm not sure how insert 'small-' @ beginning of file's name (so ./alabama/small-1.jpg).
questions:
- is there better, more robust way of creating thumbnails images located in multiple subdirectories?
- can make existing command more robust (for example, using
sedrename outputted thumbnail before saved- modify y-small.jpg part).
no need build such complicated construct. make small blocks first, connect.
i have decided not insert -small in middle of filename. makes more complicated. better use prefix (simpler code, , easier derive original filename thumb) can either thumbsdir/ or thumbsprefix-.
#!/bin/sh make_thumbnail() { pic=$1 thumb=$(dirname "$1")/thumb-$(basename "$1") convert "$pic" -thumbnail x100 "$thumb" } # need way call make_thumbnail on each file. # easiest robust way restrict on files @ level 2, , glob # */*.jpg # (we glob levels 2 , 3 2 globs: */*.jpg */*/*.jpg) pic in */*.jpg make_thumbnail "$pic" done
Comments
Post a Comment