Re: Image::Magick and perl script STDOUT problem



rbonin@xxxxxxxxx wrote:
The image magick method Write('gif:-') is supposed to write the binary
file to STDOUT. I tried adding "binmode STDOUT" before the
$image->Write command but that did not help. The STDOUT from
$image->Write('gif:-'); is not making it's way to the browser, the
browser is displaying a broken image. Looking at the raw response, I
see the correct header, just no data being sent.

Can I capture the STDOUT into a variable, and use a binary write to the
browser? I don't want to write the image to the hard drive.


<% @LANGUAGE="PerlScript" %> <% use Image::Magick;

	my $image = Image::Magick->new;
	$image->Read('W:\\in.gif');

	$Response->{ContentType} = "image/GIF";
	$image->Write('gif:-');

undef $image;

%>

Thanks
Robin


You're looking for the BinaryWrite() method:

use strict;
use warnings;
use Image::Magick;
use Win32::OLE::Variant;
our ($Response, $Request);

my $f = 'FILE_PATH';
my $i = Image::Magick->new;
$i->Read($f); # never understood IM return values ... or die $!;
my $blob = ( $i->ImageToBlob() )[0];

$Response->{contenttype} = 'image/gif';
$Response->BinaryWrite( Win32::OLE::Variant->new(VT_UI1, $blob) );

In the ActiveState documentation:

Windows Scripting => Active Server Pages
=> To Read And Display Binary Large Objects (ADO and ASP)

HTH - keith
.



Relevant Pages

  • Re: where download web application source code examples ?
    ... the header (eg Apache in Redhat 9) which means they run the cgi & buffer ... stdout, calculate the content length, then send everything back to the ... Recent versions of Apache send content back to the browser as soon ... as the cgi generates to stdout. ...
    (comp.lang.perl.misc)
  • redirect errors to browser in ruby + cgi
    ... "With some execution environments, it is be possible to have the error ... message and stack backtrace presented to you in the browser window when ... What are STDERR and STDIN and STDOUT connected to in a PCP? ... Both STDIN and STDOUT point to the browser. ...
    (comp.lang.ruby)
  • Re: simple error reporting question
    ... Jerry Stuckle wrote: ... This should send errors and warnings to stdout. ... I would expect an error/ warning reference in the browser window about the missing semi-colon. ...
    (comp.lang.php)
  • Re: simple error reporting question
    ... Rik Wasmus wrote: ... This should send errors and warnings to stdout. ... I would expect an error/ warning reference in the browser window about the missing semi-colon. ...
    (comp.lang.php)
  • Image::Magick and perl script STDOUT problem
    ... browser is displaying a broken image. ... see the correct header, ... Can I capture the STDOUT into a variable, and use a binary write to the ...
    (comp.lang.perl.misc)