PerlMagick aparently failing when called from Apache

Discussion in 'General' started by angela, Sep 9, 2010.

  1. angela

    angela New Member

    I'm migrating some perl scripts to a new server.

    Some perl routines manipulate images with PerlMagick. When I run these routines from the command line as root everything works; when I call them from a web page the routine seemingly completes (no error messages) but I get no image served.

    Some perl routines serve an image without using PerlMagick and they work just fine. The problem, I'm beginning to think, lies with getting PerlMagick working with Apache. The technique I use is to first write the page header and then write the binary image data back to the requesting browser. There is no HTML as such.

    All ImageMagick ownership and group is root with 644 chmod settings.

    I compiled ImageMagick and PerlMagick from source. Is there some security mechanism in ISPConfig3 that is preventing these compiled binaries running under Apache? Apache had modules mime and mime-magic loaded as per original configuration.

    All the routines run just fine on an old BlueQuartz CentOS 4 system.

    Any help to stop this amateur web-coder pulling hair appreciated!
     
  2. Mark_NL

    Mark_NL Member

    So you're trying to show an image in your browser with a perl script ..

    remember that you're not allowed to send a single byte extra besides the image data + it's mime type .. so the browser knows how to interpretate it..

    Read an image (png and output as jpeg):
    Code:
    use strict;
    use CGI;
    use Image::Magick;
    
    $oCGI = new CGI;
    
    print $oCGI->header( -type => "image/png", -expires => "now" );
    my $oImageMagick = new Image::Magick( format => "png" );
    $oImageMagick->Read( filename => "/some/imagefile.png" );
    binmode STDOUT;
    $oImageMagick->Write( "png:-" );
    
    It's from the top of my head, so could not work right away ;)
     
  3. angela

    angela New Member

    Thanks for wanting to help.

    I've got something similar to yourcode. The routines are already proven on my old running server.

    The only difference between my code and yours is the image I fetch remains in memory; so I do a blobToImage convert on the fetched data before pushing it out.

    Code:
     use LWP::UserAgent;
     use CGI;
     use HTTP::Cookies;
     use CGI::Carp qw/fatalsToBrowser/;
     use strict;
     use Image::Magick
    
    [snip]
    
    
          if ($secres->is_success) {
    print $query->header(-type => 'image/gif', -expires => 'now');
                binmode STDOUT, ":raw";
                my $image=Image::Magick->new(magick=>'gif');
                $image->BlobToImage($secres->{'_content'});
                $image->Threshold(threshold=>'60%');
                $image->Quantize(colors=>'8');
                $image->Sharpen(0.0x1.0);
                $image->Write('gif:-');
        }
        else {
    # bail out gracefully...
    
     [snip]
    
    
    I can get the routine to work by doing

    Code:
          if ($secres->is_success) {
     print $query->header(-type => 'image/gif', -expires => 'now');
     binmode STDOUT, "raw:";
     print $secres->{'_content'};
    }
    
    But I really need ImageMagick for its resizing and optimizations.

    And I say, it all runs from the command line just fine. I'm really mystified.
     
    Last edited: Sep 27, 2010
  4. angela

    angela New Member

    Mmm, perhaps an extreme work-around... but I changed my Linux Distro from Ubuntu to SuSe and started over with a new install.

    ImageMagick did its thing with no messing around.
     

Share This Page