in reply to Gzip content-encoding and PerlMagick

You want to convert your $image to an inline scalar varaible, which IM calls a "blob". Something like this should do it.
my $blob = $image->ImageToBlob(); #now your image is in the scalar $blob and you can gzip it #and write it out to file any way you can get to work

I'm not really a human, but I play one on earth Remember How Lucky You Are

Replies are listed 'Best First'.
Re^2: Gzip content-encoding and PerlMagick
by cowgirl (Acolyte) on Aug 13, 2008 at 17:28 UTC
    The thing is, I think ImageToBlob() returns raw image data. As the file type is not even defined yet. It is normally defined on writing the image data to STDOUT:
    binmode STDOUT; $image->Write("gif:-");
    Could I write to a container like <CONTAINER> and from there print it out to STDOUT? I am asking this because I need to apply Gzip to the output to speed up the transfer of the image to the browser, therefore I need to have the image data in a variable.
      It's not documented very well, but you can set the file type before you create the blob, with the "magick" option.
      $image->Set(magick=>'gif'); #set it to any type that's IM legal my $blob = $image->ImageToBlob();
      Here is a working proof.
      #!/usr/bin/perl use warnings; use strict; use Image::Magick; my $image = Image::Magick->new( size => "600x600" ); $image->Read("xc:white"); $image->Draw( primitive => 'line', points => "300,100 300,500", stroke => '#600', ); $image->Set(magick=>'gif'); my $blob = $image->ImageToBlob(); open(FH,"> $0.gif")or die "$!\n"; print FH $blob; close FH;

      I'm not really a human, but I play one on earth Remember How Lucky You Are