[ale] Q: q'n'd script to make 'thumbnails' with ImageMagick?

Geoffrey esoteric at 3times25.net
Wed Jul 24 23:04:35 EDT 2002


This script builds the html for you, but check it out, hack it up, throw 
it out, what ever you like. :)

Understand, it's not pretty, I threw it together pretty quickly.

John Mills wrote:
> Geoffrey -
> 
> Thanks for your help once again.
> 
> On Tue, 23 Jul 2002, Geoffrey wrote:
> 
> 
>>Actually I wrote a script to do this.  It also will rename the files to 
>>random names if you like.  One of the things my wife has on her web site 
>>are pictures of students from various activities during the year.  So, 
>>to save me the hassle of building the pages, I wrote the script.  You're 
>>welcome to it if you like, just let me know.
>>
> 
> That would be very helpful. Thanks I had in mind something like:
> 
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> #!/bin/sh
> ls *.jpg > /tmp/jpeglist
> for FILENAME in `cat /tmp/jpeglist`
> do
>  <make thumbnail and save to $FILENAME.sm>
> done
> rm /tmp/jpeglist
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> 
> That would leave me to do the HTML index manually.
> 
>  - John Mills
> 
> 
> 


-- 
Until later: Geoffrey		esoteric at 3times25.net

I didn't have to buy my radio from a specific company to listen
to FM, why doesn't that apply to the Internet (anymore...)?


#!/usr/bin/perl

# use diagnostics;

my $random="";

while ($random ne "y" && $random ne "n") {
	print "Do you want random file names? [y|n] ";
	$random = <STDIN>;
	chomp($random);
}

my $pcount = 0;

# `sed 's/main.html/gallery\\/index.html/' /var/www/html/lucy/index1.html > index1.html`;
`echo "<html><body></body></html>" > menu.html`;

my $image_dir="gallery/images";

if ( ! -d "gallery" ) { `mkdir -p $image_dir`; }
if ( ! -d "gallery/images" ) { `mkdir $image_dir`; }

open (INDEX, "> gallery/index.html");
print INDEX "<html><body bgcolor=\"white\" marginheight=0 marginwidth=0>\n" .
	"<div align=center>\n" . "<h1>More Student Photos</h1>\n" .
	"Select the small photo if you wish to see a larger image\n<p>\n" .
	"<table border=0 cellpadding=0 cellspacing=0>\n<tr>";

my $br = "";
my $count = 1;

foreach $fn (@ARGV) {

	$pcount++;
	$sf = substr($fn, index($fn, "."));

	if ($random eq "y") {
		$prefix = (int rand 500) + 100;
		while ( -f $image_dir . $prefix . $sf ) {$prefix = int rand 500 + 100;}
	} else {
		$prefix = substr($fn, 0, index($fn, "."));
	}

	$html{$fn} = $prefix . ".html";
	print "created $html{$fn} filename \n";
	$image{$fn} = $prefix . $sf;
	$thumb{$fn} = "t-" . $prefix . $sf;
	# `convert -geom 29%x29% $fn $thumb{$fn}`;
	# `convert -geom 89%x89% $fn $image{$fn}`;
	print  "moving $fn to $image{$fn}\n";
	`convert -geom 190 $fn $image_dir/$thumb{$fn}`;
	`convert -geom 570 $fn $image_dir/$image{$fn}`;
}

$prev = "";

foreach $fn (keys %html) {

	if ($prev eq "") { $first = $fn; $prev = $fn; next; }

	print "creating $html{$prev} ";
	open (HTML, "> gallery/" . $html{$prev}) or
		die "Failed to open ($html{$prev})\n";

	print HTML "<html><title>Mrs. Myers' Photo Gallery</title>\n" .
		"<body marginwidth=0 marginheight=0 bgcolor=#ffffff>\n" .
		"<div align=center>\n" .
		"Next Image\n" .
		"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\n" .
		"<a href=index.html>Back to the index</a>\n" .
		"<p>\n" .
		"<img src=images/" . $image{$prev} . ">\n" .
		"</div>\n" .
		"</body></html>\n";
	close(HTML);

	$prev = $fn;

	print INDEX "\t<td valign=top>\n\t<a href=" . $html{$prev} . ">" .
		"<img src=images/" . $thumb{$prev} . " border=0></a>\n</td>";
		$tr = (($count % 3) ) ? "" : "\n</tr><tr>";
		print INDEX "$tr \n";
		$count++;

	print "complete\n";
}

print "creating ($html{$prev}) ";
open (HTML, "> gallery/" . $html{$prev}) or
	die "Failed to open ($html{$prev})\n";

print HTML "<html><title>Mrs. Myers' Photo Gallery</title>\n" .
	"<body marginwidth=0 marginheight=0 bgcolor=#ffffff>\n" .
	"<div align=center>\n" .
	"Next Image\n" .
	"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\n" .
	"<a href=index.html>Back to the index</a>\n" .
	"<p>\n" .
	"<img src=images/" . $image{$prev} . ">\n" .
	"</div>\n" .
	"</body></html>\n";
close(HTML);

print INDEX "\t<td valign=top>\n\t<a href=" . $html{$first} . ">" .
	"<img src=images/" . $thumb{$first} . " border=0></a>\n</td>";
	$tr = (($count % 3) ) ? "" : "\n</tr><tr>";
	print INDEX "$tr \n</div>\n</table>\n</body></html>";
	$count++;

print "complete, should be $pcount photos\n";

close(INDEX);



---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.




More information about the Ale mailing list