[TriLUG] Digital Photos, Thumbnails, and Web Pages

John F. Davis davis at trilug.org
Tue Dec 6 04:27:05 EST 2005


On Mon, Dec 05, 2005 at 07:48:21AM -0500, Scott Chilcote wrote:
> Hi Folks,
> 
> After taking several pictures at our Thanksgiving event last month, I 
> got requests to send the pictures to some of my relatives.  I'm pretty 
> sure they don't want thirty or so 3-megapixel images arriving in their 
> mailboxes.
> 
...
stuff deleted
...
> 
> I'm looking for something basic.  I'd write it myself if I had less 
> going on right now.
> 
> What are other people using to accomplish this?
> 

Hello,

I wrote a simple script which generates thumbnails and creates web page
with links to them in bash.  It does not generate the thumbnails on the
fly.  Intead it simply creates them as permanent files on the disk.  In
my opinion disk space is cheap now days, but cpu cycles and time are
not.

If you are interested, here is the result

http://www.trilug.org/~davis/nov_30

and here is portion of the code:

Happy Trails,

John F. Davis

...........................
makepicpage.sh
..........................
#!/bin/bash

page="index.html"
>$page

cat ~/bin/template.head > $page


printf "<Table>\n" >> $page
let i=0;
for filename  in *.jpg *.JPG  ; do
	test -f "$filename" || continue;
	[[ "$filename" != *-t.jpg ]] || continue;
	[[ "$filename" != *-t.JPG ]] || continue;

	if ((i%5==0)) ; then 
		let j=0;
		printf "<TR>\n" >> $page
	else
		((j++))
	fi

	printf "<TD>" >> $page
	stem=${filename%.*};
	extension=${filename##*.};

	printf "<a href=\"%s\"><img src=\"%s\"></a>" "$filename" "$stem-t.$extension" >> $page
	printf "</TD>\n" >> $page

	if ((j==4)) ; then 
		printf "</TR>\n" >> $page
	fi

	((++i));

	makethumbs.sh $filename ;
	if [[ $? -ne 0 ]] ; then
		echo "failure. makethumbs.sh failed."
		exit
	fi

done


printf "</Tbody>\n" >> $page
printf "</Table>\n" >> $page

cat ~/bin/template.footer >> $page

exit

.......................
makethumbs.sh
.......................

#!/bin/bash
# check for proper parms
if [ $# -ne 1 ] ; then
	echo "usage: $0 <input file> 
	echo "eg. $0 file1.jpg 
fi

# find the file extension part
#echo $1
# %.* deletes one match of "period anything" from the end.
stem=${1%.*}
#  ##*. deletes as many matches of "anything period" that exist.
extension=${1##*.}
#echo $stem
#echo $extension


convert $1 -thumbnail 100x100 $stem-t.$extension
if [ $? -ne 0 ] ; then
	echo "failure.  convert failed to convert file."
	exit
fi





More information about the TriLUG mailing list