Images on fly using IIS

Discussion in 'Perl Misc' started by laszlo, Jun 2, 2004.

  1. laszlo

    laszlo Guest

    A have the following html file:

    <HTML><HEAD><TITLE=test</HEAD>
    <BODY><CENTER>
    <IMG SRC=http://localhost/cgi-bin/wpm/wimaker.pl/test.png>
    </CENTER></BODY></HTML>


    also the following perl file:

    #!/usr/bin/perl

    use CGI;
    use CGI::Carp;
    use Image::Magick;

    my $image = Image::Magick->new(size=>'100x100');
    $image->Read('xc:green');
    $image->Write('test.png'); #testing reasons only

    my $q = new CGI;
    $| = 1;

    print $q->header(-type=>"image/png",-expires=>"now",-status=>"200
    Document follows");
    $image->Write("png:-");

    I get a broken image, and test.png file is not written. If I delete
    $image->Write('test.png'); it will not change the result, I believe
    the problem is wimaker.pl isn't called at all.

    If I run wimaker.pl from command line test.png is created, it is
    correct image and I got the following output:

    Status: 200 Document follows
    Expires: Wed, 02 Jun 2004 22:22:52 GMT
    Date: Wed, 02 Jun 2004 22:22:52 GMT
    Content-Type: image/png

    ‰PNG

    followed with the binary data for the correct png file (the character
    before PNG stands for 0x89)

    I use WIN2000 IIS perl 5.8.0 ImageMagick 6.0.1

    How can I make wimaker.pl to be called as image generator?
    laszlo, Jun 2, 2004
    #1
    1. Advertising

  2. laszlo

    Ben Morrow Guest

    Quoth (laszlo):
    > A have the following html file:
    >
    > <HTML><HEAD><TITLE=test</HEAD>
    > <BODY><CENTER>
    > <IMG SRC=http://localhost/cgi-bin/wpm/wimaker.pl/test.png>


    This needs quoting, as it contains slashes which are special to SGML.

    <IMG SRC="http://localhost/cgi-bin/wpm/wimaker.pl/test.png">

    > </CENTER></BODY></HTML>
    >
    >
    > also the following perl file:
    >
    > #!/usr/bin/perl
    >
    > use CGI;
    > use CGI::Carp;
    > use Image::Magick;
    >
    > my $image = Image::Magick->new(size=>'100x100');
    > $image->Read('xc:green');
    > $image->Write('test.png'); #testing reasons only
    >
    > my $q = new CGI;
    > $| = 1;
    >
    > print $q->header(-type=>"image/png",-expires=>"now",-status=>"200
    > Document follows");


    binmode STDOUT;

    > $image->Write("png:-");
    >
    > I get a broken image, and test.png file is not written.


    Are you sure? I suspect is is, just not where you think. Insert

    use Cwd;

    at the top and add

    -x_cwd => cwd

    to your header call to see what the current directory is when the script is
    run.

    > If I delete
    > $image->Write('test.png'); it will not change the result, I believe
    > the problem is wimaker.pl isn't called at all.
    >
    > If I run wimaker.pl from command line test.png is created, it is
    > correct image and I got the following output:
    >
    > Status: 200 Document follows
    > Expires: Wed, 02 Jun 2004 22:22:52 GMT
    > Date: Wed, 02 Jun 2004 22:22:52 GMT
    > Content-Type: image/png
    >
    > <89>PNG
    >
    > followed with the binary data for the correct png file (the character
    > before PNG stands for 0x89)


    Are you sure? What happens if you direct output to a file and strip the
    HTTP header off? I strongly suspect the lack of binmode was corrupting
    the image.

    Ben

    --
    Joy and Woe are woven fine,
    A Clothing for the Soul divine William Blake
    Under every grief and pine 'Auguries of Innocence'
    Runs a joy with silken twine.
    Ben Morrow, Jun 3, 2004
    #2
    1. Advertising

  3. laszlo

    gnari Guest

    "laszlo" <> wrote in message
    news:...

    [CGI problem]

    > print $q->header(-type=>"image/png",-expires=>"now",-status=>"200
    > Document follows");
    > $image->Write("png:-");


    > I get a broken image, and test.png file is not written. If I delete
    > $image->Write('test.png'); it will not change the result, I believe
    > the problem is wimaker.pl isn't called at all.


    Ben has already pointed out the missing binmode here, so I will
    go slightly (or even totally) OT:

    doesn't everyone use a tool like GET or wget (or even telnet 80) in
    this situation to examine server output ?
    it amazes me to see 'I believe wimaker.pl isn't called' when
    that is such a trivial thing to test.

    gnari
    gnari, Jun 3, 2004
    #3
  4. laszlo

    John Bokma Guest

    John Bokma, Jun 3, 2004
    #4
  5. laszlo

    gnari Guest

    "John Bokma" <> wrote in message
    news:40bf0726$0$191$...
    > gnari wrote:
    >
    > > doesn't everyone use a tool like GET or wget (or even telnet 80) in
    > > this situation to examine server output ?

    >
    > I do, and tail -f access_log and a tail -f error_log


    along with massive
    print STDERR "debug\n" if $debug;

    gnari
    gnari, Jun 3, 2004
    #5
  6. laszlo

    laszlo Guest

    Ben Morrow <> wrote in message news:<c9lnfk$ceh$>...
    > Quoth (laszlo):
    > > A have the following html file:
    > >
    > > <HTML><HEAD><TITLE=test</HEAD>
    > > <BODY><CENTER>
    > > <IMG SRC=http://localhost/cgi-bin/wpm/wimaker.pl/test.png>

    >
    > This needs quoting, as it contains slashes which are special to SGML.
    >



    The resolution is:

    <IMG SRC=http://localhost/cgi-bin/wpm/wimaker.pl>

    the program reference may not be followed by additional string. I dont
    know why but in this way works neither the quoting nor binmode in the
    called program is necessary

    One more note for possibile future readers: the $| (autoflush) is
    necessary, otherwise the header will follow the image)

    thanks for the replay
    laszlo, Jun 3, 2004
    #6
  7. laszlo

    Ben Morrow Guest

    Quoth (laszlo):
    > Ben Morrow <> wrote in message news:<c9lnfk$ceh$>...
    > > Quoth (laszlo):
    > > > A have the following html file:
    > > >
    > > > <HTML><HEAD><TITLE=test</HEAD>
    > > > <BODY><CENTER>
    > > > <IMG SRC=http://localhost/cgi-bin/wpm/wimaker.pl/test.png>

    > >
    > > This needs quoting, as it contains slashes which are special to SGML.

    >
    > The resolution is:
    >
    > <IMG SRC=http://localhost/cgi-bin/wpm/wimaker.pl>
    >
    > the program reference may not be followed by additional string.


    This is then a question of server configuration. It is certainly
    possible to configure the server to cause a request for
    /cgi-bin/wpm/wimaker.pl/test.png to invoke wimaker.pl passing
    '/test.png' as a parameter; your server may not be so configured.

    > I dont know why but in this way works neither the quoting nor binmode
    > in the called program is necessary


    They are *both* necessary. The quoting of the URI has nothing to do with
    Perl: it is a question of valid HTML. binmode is *always* necessary on
    filehandles that will be fed binary data: if it happens not to have been
    what bit you in this case, it will at some point.

    Ben

    --
    perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
    qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
    1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
    2047502190/' #
    Ben Morrow, Jun 4, 2004
    #7
    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. DaveF

    animate images on the fly

    DaveF, Apr 21, 2004, in forum: ASP .Net
    Replies:
    8
    Views:
    320
    Kevin Spencer
    Apr 22, 2004
  2. cantbprince

    Creating Thumbnail Images on the fly

    cantbprince, Apr 11, 2006, in forum: Java
    Replies:
    3
    Views:
    4,777
    Oliver Wong
    Apr 11, 2006
  3. K
    Replies:
    22
    Views:
    833
  4. Draw Images on fly

    , Jun 22, 2006, in forum: ASP .Net
    Replies:
    10
    Views:
    677
  5. Brian

    Fly outmenu on the fly

    Brian, Apr 8, 2005, in forum: Javascript
    Replies:
    0
    Views:
    94
    Brian
    Apr 8, 2005
Loading...

Share This Page