Gossamer Forum
Home : General : Perl Programming :

loading images

Quote Reply
loading images
I have a webpage up and running and I have something like 200 photos I want on my webpage. It would take me a lot of time cutting and pasting code for all these pictures in html. How can I do this much easier with perl?

Let's say I want to load the images from a dir.
All have the the name: My Pictures0001, My Pictures0002, My Pictures0003 and so on.
(I can change the names to something easier. like just 0001, 0002,0003 and so on.)

It may take a large script to do this, won't it?
Does anybody know of a good script who can do this, or somebody want's to create one? I want to load the pictures in a table with 3 in the weight.
Like this:
Code:
<TABLE BORDER="0">
<TR>
<TD><IMG SRC="image.jpg" BORDER="0" WIDTH="50" HEIGHT="50" ALIGN="bottom" ALT=""></TD>
<TD><IMG SRC="image.jpg" BORDER="0" WIDTH="50" HEIGHT="50" ALIGN="bottom" ALT=""></TD>
<TD><IMG SRC="image.jpg" BORDER="0" WIDTH="50" HEIGHT="50" ALIGN="bottom" ALT=""></TD>
</TR>
<TR>
<TD><IMG SRC="image.jpg" BORDER="0" WIDTH="50" HEIGHT="50" ALIGN="bottom" ALT=""></TD>
<TD><IMG SRC="image.jpg" BORDER="0" WIDTH="50" HEIGHT="50" ALIGN="bottom" ALT=""></TD>
<TD><IMG SRC="image.jpg" BORDER="0" WIDTH="50" HEIGHT="50" ALIGN="bottom" ALT=""></TD>
</TR>
</TABLE>

Can this be done easily?

Thanks.

- perlman
Quote Reply
Re: [perlman] loading images In reply to
Give this a whirl :) ....it's untested.

Code:
#!/usr/bin/perl
#=================================
use strict;

local $SIG{__DIE__} = \&fatal;
main();
#=================================

sub main {
#-----------------------------------------------------
# Load images and turn into html.

my $path = '/path/to/your/images/directory';
my @img = ();
my $html;

opendir DIR, $path or die("Can't read $path: $!");
@img = grep /\.jpg/i, readdir(DIR);
closedir DIR;

# Generate the html.
while (@img) {
$html .= qq|<TR>\n|;
$html .= qq|<TD><IMG SRC="$_" BORDER="0" WIDTH="50" HEIGHT="50" ALIGN="bottom" ALT=""></TD>| for (splice(@img, 0, 3));
$html .= qq|</TR>\n\n|;
}

print "Content-type: text/html\n\n";
print $html;
}

sub fatal {
#-----------------------------------------------------
# Custom error.

print "Content-type: text/html\n\n";
print $_[0];
exit 1;
}
Quote Reply
Re: [Paul] loading images In reply to
Really great, Paul! Thanks.

But it didn't work. It found all the images, but it didn't display them. I added the path to the files in the image url and then it worked. Also got each of the images to become a link to their fully self.

But now all the images show on the same page, and on each line 14 pictures are displayed. For modem users this will take a while to load won't it?
I could split up the pictures in different folders and have several copies of your script.

Got any suggestions?

Thanks again Paul.

- perlman
Quote Reply
Re: [perlman] loading images In reply to
Tried the PHP script 'Gallery' available at Sourceforge?

- wil
Quote Reply
Re: [perlman] loading images In reply to
Quote:
But now all the images show on the same page,

I didn't realise you wanted a complete image gallery script Tongue

Quote:
and on each line 14 pictures are displayed.

Each line?...I'm not sure why as there are <TR></TR>'s in the code.
Quote Reply
Re: [perlman] loading images In reply to
http://gallery.menalto.com/...=News&file=index

- wil
Quote Reply
Re: [Paul] loading images In reply to
Heh..I didn't want a full gallery script. I don't need:
Quote:
Photo management includes automatic thumbnail creation, image resizing, rotation, ordering, captioning, searching and more. Albums can have read, write and caption permissions per individual authenticated user for an additional level of privacy. Give accounts to your friends and family and let them upload and manage their own photos on your website!

If I just was able to have the photos on several pages I would be satisfied! I know that takes some coding, but I hope someone will do it.

Those huge gallery scripts are way to much. Found one, but I had to install two different moduls and more.

Well, thanks for all help so far.

- perlman