Images on fly using IIS

L

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>
</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?
 
B

Ben Morrow

Quoth (e-mail address removed) (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.

</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
 
G

gnari

[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
 
L

laszlo

Ben Morrow said:
Quoth (e-mail address removed) (laszlo):

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
 
B

Ben Morrow

Quoth (e-mail address removed) (laszlo):
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top