Sidehistorik
This script travles a directory structure and creates thumbnails for each image and video (flv, avi, mov)
Bemærk |
---|
This script requires Imagick and ffmpegthumbnailer installed, this can typically be done with a package manager for the OS. Base for search is hardcoded in the script as /data/images Thumbnails are places below an image in a relative subdir called "thumbs/200pxHigh - If the Height Parameter is 200. eg. "thumbs/800pxHigh - If the Height Parameter is 800. Se "Directory Structure samples" below. Image names are kept, movies get a ".jpg" appended to their filename |
Tip |
---|
This Script is closely related to (hence used as part of) the: Script for updating my Confluence Galleries (refreshPages.sh) |
Executing the script:
Kodeblok |
---|
./makeThumbs.sh Height |
Sample
Kodeblok |
---|
./makeThumbs.sh 200 |
Parameters:
Height | Height of the thumbnails |
---|
Source of the Script:
Kodeblok | ||
---|---|---|
| ||
#!/bin/bash source config.txt IFS=$(echo -en "\n\b") Height=$1 StartDir=$2 ThumbsDir=$Height"pxHigh" LabelHeight=10 if [ $Height == '' ] then echo "Missing Height Parameter" exit 0 fi cd $StartDir for dir in `find . -type d | grep -v thumbs` do dir=$(echo $dir|sed 's/\.\///') if [ ! -d $StartDir/$dir/thumbs ] then mkdir $StartDir/$dir/thumbs fi cd $StartDir/"$dir" NumOfPics=`ls $file | egrep -i "\.(mov|flv|avi|jpg|gif|png|bmp)$" | wc -l` if [ $NumOfPics -ne 0 ] then if [ ! -d $StartDir/$dir/thumbs/$ThumbsDir ] then mkdir $StartDir/$dir/thumbs/$ThumbsDir fi for pic in `ls | egrep -i "\.(jpg|gif|png)$"` do #Create a thumbnail if the file does not exist if [ ! -f $StartDir/$dir/thumbs/$ThumbsDir/$pic ] then /usr/bin/convert -thumbnail x$Height $pic $StartDir/$dir/thumbs/$ThumbsDir/$pic echo "Converting $pic to $StartDir/$dir/thumbs/$ThumbsDir/$pic" fi done for mov in `ls | egrep -i "\.(flv|avi|mov)$"` do #Create a thumbnail if the file does not exist if [ ! -f $StartDir/$dir/thumbs/$ThumbsDir/$mov.jpg ] then /usr/bin/ffmpegthumbnailer -i $mov -o $StartDir/$dir/thumbs/$ThumbsDir/$mov.jpg -s $Height -q 10 -a echo "Thumbnailing video $mov to $StartDir/$dir/thumbs/$ThumbsDir/$mov.jpg" /usr/bin/convert $StartDir/$dir/thumbs/$ThumbsDir/$mov.jpg -pointsize 10 -background "#d5d5d5" -gravity Center label:"VIDEO" -append $StartDir/$dir/thumbs/$ThumbsDir/$mov.jpg echo "Labeling video $StartDir/$dir/thumbs/$ThumbsDir/$mov.jpg" fi done fi done |
Directory structure sample:
Original file | Thumbnail for 200 Height | Thumbnail for 800 Height | ||
---|---|---|---|---|
/data/images/MyCar/image1.jpg | /data/images/MyCar/thumbs/200pxHigh/image1.jpg | /data/images/MyCar/thumbs/800pxHigh/image1.jpg | ||
/data/images/MyCar/Styled/image1.jpg | /data/images/MyCar/Styled/thumbs/200pxHigh/image1.jpg | /data/images/MyCar/Styled/thumbs/800pxHigh/image1.jpg | ||
/data/images/MyCar/Speeding.avi | /data/images/MyCar/thumbs/200pxHigh/Speeding.avi.jpg |