Initial working commit
Stripped sensitiv information
This commit is contained in:
86
piwigo_thumbgen.sh
Executable file
86
piwigo_thumbgen.sh
Executable file
@@ -0,0 +1,86 @@
|
||||
#!/bin/bash
|
||||
#Author: Poul Serek
|
||||
|
||||
shopt -s globstar
|
||||
|
||||
#echo "Starting Piwigo thumbnail generation"
|
||||
|
||||
#Remember a trailing '/'
|
||||
sourceDir="$1"
|
||||
destDir="$2"
|
||||
|
||||
echo "Source: $sourceDir"
|
||||
echo "Dest: $destDir"
|
||||
|
||||
counter=0
|
||||
fnNoExt=""
|
||||
fnExt=""
|
||||
fnPath=""
|
||||
|
||||
STARTTIME=$(date +%s)
|
||||
|
||||
# drop CIFS cache in case target files existed before
|
||||
sync; echo 3 > /proc/sys/vm/drop_caches;
|
||||
|
||||
for file in "$sourceDir"/**/*.{jpg,JPG,jpeg,JPEG}
|
||||
do
|
||||
if [[ ! -f "$file" ]]
|
||||
then
|
||||
continue
|
||||
fi
|
||||
|
||||
case $file in
|
||||
*[[:space:]]*)
|
||||
# replace all blanks
|
||||
mv "${file}" "${file// /_}"
|
||||
file=${file// /_}
|
||||
echo "Space replaced: ${file}"
|
||||
;;
|
||||
esac
|
||||
|
||||
fnNoExt="${file%.*}"
|
||||
fnExt="${file##*.}"
|
||||
fnPath="${file%/*}"
|
||||
fnPath="${fnPath#$sourceDir}"
|
||||
fnNoExt="${fnNoExt#$sourceDir}"
|
||||
|
||||
#echo "${fnPath} ${fnNoExt}"
|
||||
|
||||
#If the medium thumbnail exists we assume that the rest also exists and skip this image
|
||||
if [ ! -f "${destDir}${fnNoExt}-me.${fnExt}" ]; then
|
||||
|
||||
mkdir -p "${destDir}${fnPath}"
|
||||
|
||||
#Error checking
|
||||
result=$(jpeginfo -c "$file")
|
||||
if [[ $result != *"[OK]"* ]]
|
||||
then
|
||||
echo $result
|
||||
fi
|
||||
|
||||
# Auto rotate source image according to exif orientation information
|
||||
orient=$(exiftool -Orientation "${file}")
|
||||
if [ ! -z "${$orient##*"normal"*}" ]; then
|
||||
mogrify -auto-rotate -quality 94 "${file}" #> /dev/null 2>&1
|
||||
fi
|
||||
#echo "MISSING! ${destDir}${fnNoExt}-me.${fnExt}"
|
||||
#Store correctly oriented base image (medium) in memory. All other thumbnails are created from this
|
||||
convert "${file}" -auto-orient -thumbnail 1008x756^ -write mpr:baseline +delete \
|
||||
mpr:baseline -write "${destDir}${fnNoExt}-la.${fnExt}" +delete \
|
||||
mpr:baseline -thumbnail 792x594 -write "${destDir}${fnNoExt}-me.${fnExt}" +delete \
|
||||
mpr:baseline -thumbnail 150x9999 -write "${destDir}${fnNoExt}-cu_s150x9999.${fnExt}" +delete \
|
||||
mpr:baseline -thumbnail 144x144 -write "${destDir}${fnNoExt}-th.${fnExt}" +delete \
|
||||
mpr:baseline -define jpeg:size=144x144 -thumbnail 120x120^ -gravity center -extent 120x120 "${destDir}${fnNoExt}-sq.${fnExt}"
|
||||
#mpr:baseline -resize 240x240 -write "${destDir}${fnNoExt}-2s.${fnExt}" +delete \
|
||||
fi
|
||||
counter=$[$counter +1]
|
||||
if [ $(($counter%100)) -eq 0 ]; then
|
||||
ENDTIME=$(date +%s)
|
||||
echo "Processed: ${counter} - Executing for $((($ENDTIME - $STARTTIME)/60)) minutes"
|
||||
fi
|
||||
done
|
||||
|
||||
chown -R www-data: ${destDir}
|
||||
|
||||
ENDTIME=$(date +%s)
|
||||
echo "It took $((($ENDTIME - $STARTTIME)/60)) minutes to complete this task..."
|
Reference in New Issue
Block a user