Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
There is a small piece of code that does what I expect it to:
#!/usr/bin/perl use Image::Magick; $ipimage = Image::Magick->new(size=>'640x480'); $ipimage->Read("logo:"); $blob1=$ipimage->ImageToBlob(); $opimage = Image::Magick->new(size=>'640x480'); $opimage->BlobToImage($blob1); $opimage->Write("t1.jpg");
It writes a JPEG of the ImageMagick logo. Here is a second piece of code. The only difference is that I have specified an RGB format for the image:
#!/usr/bin/perl use Image::Magick; $ipimage = Image::Magick->new(size=>'640x480'); $ipimage->Set(magick=>'RGB'); $ipimage->Read("logo:"); $blob1=$ipimage->ImageToBlob(); $opimage = Image::Magick->new(size=>'640x480'); $opimage->Set(magick=>'RGB'); $opimage->BlobToImage($blob1); $opimage->Write("t2.jpg");
In this case, the output is still a 640x480 JPEG image. However, the icon is a quarter the size, it's repeated in the top left and right quadrants (the lower half of the image being black) and the image colours are wrong.

I have looked for any worked examples of BlobToImage and come up with nothing. What documentation I have found seems to be abstract API definitions, but without enough information to say for sure if I'm calling it correctly. I'd really appreciate someone explaining to me why I get these different outputs, and how to call BlobToImage for an RGB image (since I need to manipulate the individual colour pixels and GetPixel/SetPixel is far too slow) to create the sort of output that the first code example gives.

With thanks

In reply to ImageMagick - why do these snippets act differently? by pete_l

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible editor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2021-05-12 13:20 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (127 votes). Check out past polls.