I wasn't sure if I should post here, or in the cgi forums, but I think my problem is more perl than anything else. This script
goes through my uploads folder and if it finds a .jpg which hasn't been resized, will do so. That part works great. The foreach loop which displays the link/image, won't pick up the new thumbnail the first time around. But when I click 'refresh' on the browser, they are there.
Also should I separate the 'resize' portion from the cgi script? No issues yet, but maybe will cause page to load slower. I would prefer to have it all in one click if possible. Thanks for any suggestions-
Because a thing seems difficult for you, do not think it impossible for anyone to accomplish.
Marcus Aurelius
Code:
#!/usr/bin/perl
use CGI qw(:standard);
use Image::Magick;
print header;
print "<link rel=\"stylesheet\" ";
print "type=\"text\/css\" href=\"\/uploads/default\.css\">"."\n";
print "<BODY bgcolor=\"999966\">";
[...]
print "<h2>Files Currently in photo folder:</h2>\n";
opendir(DIR, "/var/[URL unfurl="true"]www/uploads");[/URL]
@photo=grep(/\.jpg/i,readdir(DIR));
closedir(DIR);
[...]
my $im = Image::Magick->new;#found this section over at perlmonks...
my (@photo) = @photo;
for (@photo) {
if (/ /) {
my $old = $_;
tr, ,_,s;
$_ .= ".jpg" unless /\.jpg$/;
! -e and rename $old, $_ or next;
warn "renaming $old to $_\n";
}
next if /\.thumb\.jpg$/;
my $thumb = "$_.thumb.jpg";
next if -e $thumb;
undef @$im;
my $ret;
$ret = $im->Read($_)
and warn($ret), next;
$ret = $im->Scale(geometry => '100x100')
and warn($ret), next;
$ret = $im->Write($thumb)
and warn($ret), next;
warn "thumbnail made for $_\n";
}
foreach $file (sort @photo){
if ($file !~ /thumb/){print "<a href=\"\/uploads\/$file\">$file</a><br>";}
if ($file =~ /thumb/){print "<img src=\"\/uploads\/$file\" border=0 width=\"40\" height=\"40\"><br>";}
}
print end_html;
Also should I separate the 'resize' portion from the cgi script? No issues yet, but maybe will cause page to load slower. I would prefer to have it all in one click if possible. Thanks for any suggestions-
Because a thing seems difficult for you, do not think it impossible for anyone to accomplish.
Marcus Aurelius