darkphorm has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use CGI; use Image::Magick; use CGI::Carp qw(fatalsToBrowser); my $cgi = new CGI; $magick=Image::Magick->new(); $images=Image::Magick->new(); ######## my $basepath = "/websites/snowbunny/www"; my $path = $cgi->url_param("path"); my %filetypes; $filetypes{jpg}="jpeg"; $filetypes{gif}="gif"; #### $path =~ tr/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345 +6789\ \_\-\///c; $path =~ s/\/\///gis; $path =~ s/\.\.//gis; $path = "gallery1/dec_2004"; my $fullpath = "$basepath/$path"; #Just in case the cgi path was mangled, but it isn't!!! $fullpath="/websites/phorm/www/pics/animals"; if ( -d $fullpath ) { opendir(DIR, "$fullpath"); @files = readdir(DIR); my @pictures; my $picture_count; foreach $file(@files) { # warn("Checking $file"); if ($file =~ /\.([\w\d]+)$/) { $extension = lc($1); if ( defined($filetypes{$extension} ) ) { my $filepath = "$fullpath/$file"; #$filepath =~ s/\ /\\\ /gi; $pictures[$picture_count] = Image::Magick->new(); warn("# of pictures: " . @$images); open (IMAGE_IN, "<$filepath") or die("Cannot read file $filepa +th\n$!"); #pictures[$picture_indx] = $pictures[$picture_count]->ReadImag +e("$filepath") or die("Cannot read $filepath"); # $pictures[$picture_indx] = $pictures[$picture_count]->Read(fil +e=>\*IMAGE_IN) or die("Error reading file $filepath $!"); close(IMAGE_IN); $pictures[$picture_count]->Label("$filename"); push(@$images, $pictures[$picture_indx] ); $picture_count++; } } } if ( $picture_count > 0) { my $montage=$images->Montage(geometry=>'130x194+10+5>',gravity +=>'Center', bordercolor=>'green',borderwidth=>1,tile=>'5x1000',compose=> +'over', background=>'#ffffff',font=>'Generic.ttf',pointsize=>18,fi +ll=>'#600', stroke=>'none'); $montage->Set(matte=>'false'); print "Content-type: image/jpeg\n\n"; $montage->Write('jpg:-'); } else { print "Content-type: text/html\n\n"; print "no pictures in $fullpath"; } } else { die("Invalid path $fullpath"); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: PerlMagick "file not found" issues
by g0n (Priest) on Mar 17, 2005 at 11:30 UTC | |
by darkphorm (Beadle) on Mar 17, 2005 at 16:43 UTC | |
|
Re: PerlMagick "file not found" issues
by PodMaster (Abbot) on Mar 18, 2005 at 07:43 UTC |