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

I come looking for guidance.

I have wrtten image creation code using Image::Magick

This works ok on my test machine running under apache and win32, however when I run it under apache/linux I get the dreaded :"Premature end of script headers: " in the error logs.

I've chmoded the script 755, uploaded in ascii
=============the code=============

#!/usr/local/bin/perl # # Make simple beveled button and output to STDOUT in GIF format # # to embed this image in a web page, use: # img src="imagedemo.pl" use Image::Magick; #print "Content-type: image/gif\n\n"; # #$image = Image::Magick->new; #$image->Set(size=>'30x180'); #$image->Read("gradient:#ff0000-#0000ff"); #$image->Raise('3x3'); #$image->Rotate(-90); #$image->Write('gif:-'); exit(0);
===============================

My host tells me that image magick is installed; the script falls at the use statement uncommented above..

any meditative thoughts??

Replies are listed 'Best First'.
Re: Problem using Image::Magick
by dws (Chancellor) on Apr 16, 2003 at 16:49 UTC
    The error you're seeing ("Premature end of script headers"), is the web server's way of telling the browser that the script terminated without sending the appropriate HTTP response headers. You have code to send a response header, but it's commented out.   #print "Content-type: image/gif\n\n"; The web server doesn't get see a Content-type header from the script, and passes along the error that you're seeing. There might be a problem finding Image::Magick, or there might not. You won't know without further exploration.

    Since you appear to be new to CGIs, let me suggest a two-step debugging process that will start to give you some experience and confidence. First, try the simple script

    #!/usr/bin/perl print "Content-type: text/plain\n\n"; print "It works!\n";
    Assuming this works, try
    #!/usr/bin/perl use Image::Magick; print "Content-type: text/plain\n\n"; print "It still works!\n";
    If this fails, your ISP hasn't installed Image::Magick. If it works, however, you're on your way. Uncomment the lines in your script and try again.

    Your server's error logs, if you have access to them, might also provide some useful information.

Re: Problem using Image::Magick
by VSarkiss (Monsignor) on Apr 16, 2003 at 16:47 UTC

    The next question is, "installed where?" If it's not in your @INC array, Perl won't find it. An easy way to add the directory that it's installed in is to use lib 'directory'; beforehand.

    Another problem may be permissions. Once you know where it is, check that you can read it.

Re: Problem using Image::Magick
by gmpassos (Priest) on Apr 17, 2003 at 05:43 UTC
    Take a look in your WebLog and see the error msg!

    Or make this to see if Image::Magick is working:

    !/usr/local/bin/perl print "Content-type: text/html\n\n" ; print "<pre>\n" ; eval{ use Image::Magick ;}; print "$@\n" ; eval{ my $image = Image::Magick->new ;} ; print "$@\n" ; print "</pre>\n" ;

    Check you Perl path too! I use: #!/usr/bin/perl

    And make a simple script to see if Perl works:

    #!/usr/bin/perl print "Content-type: text/html\n\n" ; print "Hello!\n" ;

    Note that exit(0) can be interpreted as error in some OS!

    Graciliano M. P.
    "The creativity is the expression of the liberty".

Re: Problem using Image::Magick
by Improv (Pilgrim) on Apr 16, 2003 at 16:47 UTC
    What version of Linux are you using? Could it be that you're running apache chrooted? If so, you'll need to make your modules available to the perl that's inside the chrooted environment. What happens if you use sudo to attempt to run your script as the apache user?