in reply to Re: Gzip content-encoding and PerlMagick
in thread Gzip content-encoding and PerlMagick

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.

Replies are listed 'Best First'.
Re^3: Gzip content-encoding and PerlMagick
by zentara (Cardinal) on Aug 13, 2008 at 18:14 UTC
    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