Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Problem with the GD module

by ido50 (Scribe)
on Aug 14, 2003 at 19:23 UTC ( [id://283976]=perlquestion: print w/replies, xml ) Need Help??

ido50 has asked for the wisdom of the Perl Monks concerning the following question:

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

Replies are listed 'Best First'.
Re: Problem with the GD module
by Beatnik (Parson) on Aug 15, 2003 at 00:52 UTC
    GD uses libgd... and libgd needs the JPEG libs installed. So even if the server has libjpeg installed, it doesn't mean libgd has it enabled. Rebuilding libjpeg wont fix this. Rebuilding libgd might (but I won't guarantee).

    Greetz
    Beatnik
    ... I'm belgian but I don't play one on TV.
Re: Problem with the GD module
by jmanning2k (Pilgrim) on Aug 14, 2003 at 20:55 UTC
    You still have use lib before use GD, so you are probably using your private version of GD. Odds are, you didn't build it with jpeg support when you installed your own version (or didn't upload the autoload and non-native perl bits for the proper arch - FreeBSD).

    Remove the use lib line so you use the installed GD, and trust the sysadmin. You might also want to remove GD.pm from your private perllib path, just to avoid confusion.

    ~Jon

      Thanks jmanning2k for your answer, but I've already deleted "my own" GD.pm, and removing the use lib line doesn't help.
      Now about this: "Odds are, you didn't build it with jpeg support when you installed your own version (or didn't upload the autoload and non-native perl bits for the proper arch - FreeBSD)". Part from being able to upload the GD.pm file, can I actually upload and build gd myself?!

      -------------------------
      Live fat, die young
        If you have a shell account on the machine in question, it's likely. Get the libgd source and unpack it to ~/src/libgd/. Compile it with the right options (point to the installed libjpg, libpng, lib(un)gif, etc) - ./configure --help will be useful here. Don't forget to set the install prefix to ~/lib/.

        Then compile your GD.pm module on the remote system, pointing to your custom installation of libgd in ~/lib.

        You can't compile it locally, then upload it, unless you have the exact same version of FreeBSD and related libraries that are on the remote system.

        Seriously though, if you have a willing sysadmin, let him do it. Unless you don't trust him, or don't trust that the module is built correctly... In that case, it would be best to find some sort of test program that uses libgd (other than GD.pm) and verify jpeg is broken before trying to compile it yourself. It's very likely that libgd and GD.pm are correct and your problem is just something minor elsewhere. Break it down to the simplest blocks and test each component in the chain -- libjpeg, libgd, GD.pm, your script.

        Hope this helps...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://283976]
Approved by fglock
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2024-04-19 09:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found