Imager module to resize a GIF

Discussion in 'Perl Misc' started by Jason C, Oct 19, 2011.

  1. Jason C

    Jason C Guest

    I have a web script that resizes images uploaded by the site visitor to predetermined dimensions. This works fine for JPG and PNG, but not for GIF.

    I've just about copied the script verbatim from CPAN for testing, but getwidth(), etc, all return nothing:

    #!/usr/bin/perl
    #
    use CGI::Carp qw(fatalsToBrowser);
    use Imager;
    use strict;
    use warnings;

    my $img = Imager->new();
    $img->open(file=>'/home/myacct/www/myimage.gif', type=>'gif')
    or die "not read";

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

    if (-e "/home/myacct/www/myimage.gif") {
    print "Image information:\n";
    print " Width: ". $img->getwidth() ."\n";
    print " Height: ". $img->getheight() ."\n";
    print " Type: ". $img->type() ."\n";
    }

    else { print "not found"; }
    exit;

    http://search.cpan.org/~tonyc/Imager-0.85/lib/Imager/ImageTypes.pod

    It prints "Image information", etc, so the image is found... it's just not being read.

    I do have giflib installed on the server. I wasn't sure if I installed it before or after Imager, though, so I uninstalled Imager and reinstalled it, but that had no impact.

    If any of you are familiar with Imager, is there something else that I need to do in order to get it to recognize GIF files?
    Jason C, Oct 19, 2011
    #1
    1. Advertising

  2. Jason C

    Jason C Guest

    On Wednesday, October 19, 2011 8:20:50 AM UTC-4, Ben Morrow wrote:
    > What you have there works for me, here. Do you, in fact, have a .pm and
    > a .so for Imager::File::GIF? If you run ldd against the .so (which
    > should be somewhere like /usr/local/lib/perl5/site_perl/5.12.4/
    > amd64-freebsd/auto/Imager/File/GIF/GIF.so) are all the libraries it
    > needs found?
    >
    > Is there something wrong with your gif file? There is a file called
    > GIF/testimg/expected.gif in the Imager distribution; since that's the
    > file Imager uses to make sure giflib works, you could try that (it
    > should be 16x16px).
    >
    > Ben


    You're right, it's more likely that there's something missing on the server.. I thought that the Imager package would include everything it needed, butI guess not.

    I don't see Imager::File::GIF in my list of installed modules (from WHM/cPanel), so I tried to install it manually. The install failed with:

    perl-64bit-hack: enabled
    GIF: building independently
    GIF: main: includes not found - libraries not found
    GIF: Checking if the compiler can find them on its own
    GIF: Test code failed: Can't link/include 'gif_lib.h', 'stdio.h', 'gif'
    OS unsupported: GIF libraries or headers not found
    No 'Makefile' created TONYC/Imager-File-GIF-0.81.tar.gz
    /usr/local/cpanel/scripts/cpan_sandbox/x86_64/perl Makefile.PL OTHERLDFLAGS=-L/usr/lib64 LDFLAGS=-L/usr/lib64 EXTRALIBDIR=/usr/lib64 -- NOT OK
    Running make install
    Make had some problems, won't install
    Could not read metadata file. Falling back to other methods to determine prerequisites
    perlmod--Install done


    I also tried to install it via SSH, like so:

    perl -MCPAN -e shell;
    install Imager::File::GIF

    And received the same error. I even tried:

    force install Imager::File::GIF

    With the same result.

    Interestingly, my modules go to /usr/lib/perl5/site_perl/5.8.8, but I don'tsee Imager installed there at all! And I definitely don't have Imager/File/GIF. Imager is working, though, so it exists somewhere... I just don't know where. Could this be why it's failing?
    Jason C, Oct 20, 2011
    #2
    1. Advertising

  3. Jason C <> writes:

    [...]

    > I don't see Imager::File::GIF in my list of installed modules (from WHM/cPanel), so I tried to install it manually. The install failed with:
    >
    > perl-64bit-hack: enabled
    > GIF: building independently
    > GIF: main: includes not found - libraries not found
    > GIF: Checking if the compiler can find them on its own
    > GIF: Test code failed: Can't link/include 'gif_lib.h', 'stdio.h',
    > 'gif'


    According to

    http://www.google.com/#hl=en&sugexp....,cf.osb&fp=b24facda13a68307&biw=1537&bih=858

    this should mean that you're either missing the giflib library,

    http://giflib.sourceforge.net

    or (if you are using a package provided by some Linux distribution)
    the corresponding 'development' package which would usually include
    the headers (since disks are so tiny nowadays and just keep shrinking
    and shrinking, Linux distributors have commonly chosen that the
    overhead of having a bunch of possibly unused text files installed
    would be too much for 'end users' to bear, given that only relatively
    few of them will likely ever compile something on their computers
    ....).
    Rainer Weikusat, Oct 20, 2011
    #3
  4. Jason C

    J. Gleixner Guest

    On 10/20/11 00:47, Jason C wrote:
    > On Wednesday, October 19, 2011 8:20:50 AM UTC-4, Ben Morrow wrote:
    >> What you have there works for me, here. Do you, in fact, have a .pm and
    >> a .so for Imager::File::GIF? If you run ldd against the .so (which
    >> should be somewhere like /usr/local/lib/perl5/site_perl/5.12.4/
    >> amd64-freebsd/auto/Imager/File/GIF/GIF.so) are all the libraries it
    >> needs found?
    >>
    >> Is there something wrong with your gif file? There is a file called
    >> GIF/testimg/expected.gif in the Imager distribution; since that's the
    >> file Imager uses to make sure giflib works, you could try that (it
    >> should be 16x16px).
    >>
    >> Ben

    >
    > You're right, it's more likely that there's something missing on the server. I thought that the Imager package would include everything it needed, but I guess not.
    >
    > I don't see Imager::File::GIF in my list of installed modules (from WHM/cPanel), so I tried to install it manually. The install failed with:
    >
    > perl-64bit-hack: enabled
    > GIF: building independently
    > GIF: main: includes not found - libraries not found

    ^^^^^^^^^^^^^^^^^^^
    > GIF: Checking if the compiler can find them on its own
    > GIF: Test code failed: Can't link/include 'gif_lib.h', 'stdio.h', 'gif'
    > OS unsupported: GIF libraries or headers not found


    [...]

    You probably need to have the various gif, jpeg, etc. libraries
    installed, or possibly modify your Include path. See the README
    file, which is part of the distribution, or you can view it online:
    http://cpansearch.perl.org/src/TONYC/Imager-0.85/README

    >
    > Interestingly, my modules go to /usr/lib/perl5/site_perl/5.8.8, but I don't see Imager installed there at all! And I definitely don't have Imager/File/GIF. Imager is working, though, so it exists somewhere... I just don't know where. Could this be why it's failing?


    To see where the module is located, try: perldoc -l Imager
    J. Gleixner, Oct 20, 2011
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew

    Raw Imager

    Andrew, Feb 19, 2007, in forum: Python
    Replies:
    0
    Views:
    342
    Andrew
    Feb 19, 2007
  2. imager sample for text

    , Jan 17, 2007, in forum: Perl Misc
    Replies:
    2
    Views:
    96
  3. joe

    Imager with UTF8

    joe, Nov 25, 2008, in forum: Perl Misc
    Replies:
    3
    Views:
    98
    RedGrittyBrick
    Nov 25, 2008
  4. jwcarlton

    Imager module with GIFs

    jwcarlton, Feb 22, 2011, in forum: Perl Misc
    Replies:
    10
    Views:
    177
    Uri Guttman
    Feb 24, 2011
  5. Ivan Shmakov
    Replies:
    17
    Views:
    637
    Ivan Shmakov
    Jun 28, 2013
Loading...

Share This Page