Thumbnail creation from shell possible?

Phoca Gallery - image gallery extension
marcel77
Phoca Enthusiast
Phoca Enthusiast
Posts: 79
Joined: 22 Apr 2016, 12:03

Re: Thumbnail creation from shell possible?

Post by marcel77 » 14 Sep 2016, 22:12

Here is a first draft

@Jan: If you don´t wish something like this, please delete!

CAUTION:
It may not be free from errors. Please work with backups only! USING at YOUR OWN RISK!!!

I put the code in a file in /usr/scripts with name mk_thumbnails and start with /usr/scripts/mk_thumbnails from within the start folder. The script works with 1 level subdirectories it ignors the "thumbs" folder and shouldn´t overwrite exisiting files. you can find the resolution within the script. I use S = 55x44, m = 201x134 and l=800x534. If you specify a watermark file, it adds a watermark, if watermark file exists.

For me it´s working fine with big folder. With the PhocaGallery build in function I need 1 to 4 seconds for each picture. Directly on my webserver this script create thumbnails for 10 pictures within a second.

Maybe someone has more ideas:

Code: Select all

#!/bin/bash

# script creating thumbnails for Phoca Gallery directly from shell
# USING AT YOUR OWN RISK!!!
# first draft, 14.09.2016 Marcel77
# Define everthing you need before the doted line
# And start it from within the folder with pictures.
PATH_TO_WATERMARK="/COMPLETE/PATH/watermark-large.png"
L_SIZE="800x534"
M_SIZE="201x134"
S_SIZE="66x44"
#............................................................................................................

pfad=`pwd`
echo "$pfad"
echo

sudo find "$pfad" -maxdepth 1 -mindepth 0 -type d |
while read pfadname
do
	END_OF_PATH=`basename "${pfadname}"`
	if [ "$END_OF_PATH" != "thumbs" ];
	then
		#echo "$END_OF_PATH" 
		if ! [ -e "${pfadname}/thumbs" ];
		then
			mkdir "${pfadname}/thumbs"
		fi
		sudo find "$pfadname" -maxdepth 1 -mindepth 1 -iname '*.jpg' |
		while read dateiname
		do
			dateiop=`basename "$dateiname"`
			#echo ${dateiop}
			if ! [ -e "${pfadname}/thumbs/phoca_thumb_s_$dateiop" ];
			then
				echo "create phoca_thumb_s_$dateiop" 
				convert -resize $S_SIZE "$dateiname" "${pfadname}/thumbs/phoca_thumb_s_$dateiop"
			fi
			if ! [ -e "${pfadname}/thumbs/phoca_thumb_m_$dateiop" ];
			then
				echo "create phoca_thumb_m_$dateiop" 
				convert -resize $M_SIZE "$dateiname" "${pfadname}/thumbs/phoca_thumb_m_$dateiop"
			fi
			if ! [ -e "${pfadname}/thumbs/phoca_thumb_l_$dateiop" ];
			then
				echo "create phoca_thumb_l_$dateiop" 
				convert -resize $L_SIZE "$dateiname" "${pfadname}/thumbs/phoca_thumb_l_$dateiop"
				if [ -e "$PATH_TO_WATERMARK" ];
				then
					composite -gravity center "$PATH_TO_WATERMARK" "${pfadname}/thumbs/phoca_thumb_l_$dateiop" "${pfadname}/thumbs/phoca_thumb_l_$dateiop"
				else
					echo "No watermark file"
				fi
			fi
		done
	fi
done

Tags:

User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 44227
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Thumbnail creation from shell possible?

Post by Jan » 18 Sep 2016, 14:07

Hi, thank you very much for the bash script.

Maybe someone has more ideas
Unfortunately, my skills regarding bash scripting is very limited, so no ideas from my sides, but maybe someone ...

Thank you, Jan
If you find Phoca extensions useful, please support the project

Post Reply