Well I'm not so sure the problem is related to the module or to the library. The problem is as such:
I've created a program that creates thumbnails to jpeg and png files in a certain directory.
When trying to use the newFromJpeg subroutine in my program (Running on my site's FreeBSD server, on my computer it works fine), I get an error that libgd was not built with jpeg support. Well, probably libgd was not build with jpeg support. Only that the server's administrator assured me that jpeg support was installed and even reinstalled it to make sure.
Now the thing is that at first I didn't know the GD module was installed in the server and uploaded it myself (and
used
lib on the directory to which I uploaded). I've tried some times and got some error messages (Until I realised it was installed). At a certain point, when checking the picture directory, I noticed that thumbnails for jpeg files where actually created. So libgd must have been installed with jpeg support. The administrator claims the GD Module's version is 2.07 (Latest). Anyone has an idea what might cause this?
Here's the program in case it helps:
#!/usr/bin/perl -w
BEGIN {
$|=1;
print "Content-type: text/html\n\n";
use CGI::Carp('fatalsToBrowser');
}
use lib "/path-to-perl-modules";
use GD;
use CGI;
use strict;
my $directory = "/path-to-pics";
my $thumbdir = "/path-to-pics/thumbs";
my $url = "http://www.www.com/cgi-bin";
my @dirs = getdirs($directory);
for my $dir (@dirs) {
update($dir);
}
print "Thumbnails created/updated successfully";
sub getdirs {
my $directory = shift;
my @dirs;
opendir (DIR, $directory);
my @files = grep { !/^\.\.?$/ } readdir DIR;
closedir DIR;
push (@dirs, $directory);
for my $file (@files) {
if (-d "$directory/$file") {
getdirs("$directory/$file");
}
}
return @dirs;
}
sub update {
my ($directory) = shift;
my ($image, $desimage);
opendir (DIR, $directory);
my @files = grep { !/^\.\.?$/ } readdir DIR;
closedir DIR;
for my $file (@files) {
my $full = "$directory/$file";
if (-f $full && $full =~ m/\.(png|jpg)/i) {
my $extension = $1;
open (PNG, "$full") || die;
if ($extension eq "png") {
$image = newFromPng GD::Image(\*PNG) || die;
} else {
$image = newFromJpeg GD::Image(\*PNG) || die;
}
close PNG;
my ($width,$height) = $image->getBounds();
if ($width <= 250 && $height <= 250) {
# DO NOTHING
} else {
if ($width <= 250 && $height > 250) {
my $percent = (250*100)/$height;
my $newidth = ($width*$percent)/100;
$desimage = new GD::Image($newidth, 250);
$desimage->copyResized($image, 0, 0, 0, 0, $newidth, 250, $w
+idth, $height);
} elsif ($width > 250 && $height <= 250) {
my $percent = (250*100)/$width;
my $newheight = ($height*$percent)/100;
$desimage = new GD::Image(250, $newheight);
$desimage->copyResized($image, 0, 0, 0, 0, 250, $newheight,
+$width, $height);
} else {
if ($width > $height) {
my $percent = (250*100)/$width;
my $newheight = ($height*$percent)/100;
$desimage = new GD::Image(250, $newheight);
$desimage->copyResized($image, 0, 0, 0, 0, 250, $newheight
+, $width, $height);
} else {
my $percent = (250*100)/$height;
my $newidth = ($width*$percent)/100;
$desimage = new GD::Image($newidth, 250);
$desimage->copyResized($image, 0, 0, 0, 0, $newidth, 250,
+$width, $height);
}
}
$file =~ m/^(.+)\.\w+$/;
my $new = "${file}.png";
open (FILE, "+>$thumbdir/$new") or die "Can't open file: $!";
binmode FILE;
print FILE $desimage->png;
close FILE;
}
}
}
}
-------------------------
Live fat, die young
edited by ybiC: balanced <readmore> tags