DigiKam to PHP Photo Album - Thumbnail Generation

DigiKam to PHP Photo Album - Thumbnail Generation

DigiKam to PHP Photo Album - Thumbnail Generation

I have a shell script that runs hourly:

2 * * * * /mydata/Pictures_tools/generate_thumbnails.sh

The shell script uses locks to ensure that only one instance of it is running at a time (it can take a while to generate a lot of thumbnails if a large number of images are added/updated).

The script only generates thumbnails for images that have not already had a thumbnail generated.

`

#!/bin/sh

set -e

(

flock -x -w 10 200

cd /mydata/
find Pictures -type f -name '*.[Jj][Pp][Gg]' -print | 
while read file
do
	thumbdir="./Pictures_Resized/`dirname \"$file\"`"
	if [ \! -d "$thumbdir" ] ; then
		echo "`date` making $thumbdir"
		mkdir -p "$thumbdir"
	fi

	# convert to a 160x120 crop to fit
	target="./Pictures_Resized/${file%%.[Jj][Pp][Gg]}-160x120.JPG"
	if [ \! -f "$target" -o "$file" -nt "$target" ] ; then 
		echo "`date` creating $target";
		convert "$file" -auto-orient -strip -resize 160x120^ -gravity center -extent 160x120  "$target"
	fi

	# convert to 1024x768 - this should be a max in each direction
	target="./Pictures_Resized/${file%%.[Jj][Pp][Gg]}-1024x768.JPG"
	if [ \! -f "$target" -o "$file" -nt "$target" ] ; then 
		echo "`date` creating $target";
		convert "$file" -auto-orient -resize 1024x768 "$target"
	fi

done;

) 200>/var/lock/generate_thumbnails_2.sh

`