Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: About GD Image Data Output Methods

by BrowserUk (Patriarch)
on Jun 07, 2015 at 17:48 UTC ( [id://1129361]=note: print w/replies, xml ) Need Help??


in reply to About GD Image Data Output Methods [SOLVED]

Karl, try using this to convert the internal gd format to a Windows .BMP format. After that, any of your image converters should be able to port it to whatever format you require.

# ... $image is your GD::Image for output my $gd = $image->gd; my @attrs = unpack 'nnnCV', substr( $gd, 0, 11, '' ); my $len = length( $gd ) / 4 * 3; my $bmp = pack 'a2 V V V l< l< l< v v V V l< l< V V', 'BM', $len + 54, 0, 54, 40, $attrs[1], $attrs[2], 1, 24, $len, 0, +0, 0, 0; $bmp .= join'', unpack '(xaaa)*', $gd; ## Now print $bmp to a file xxx.bmp and convert; or maybe pipe directl +y to an image converter for conversion.

It's a bit "magic number" ladened, but that's all they are; magic numbers.

Yell, if you really need the explanation :)


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

Replies are listed 'Best First'.
Re^2: About GD Image Data Output Methods
by karlgoethebier (Abbot) on Jun 07, 2015 at 19:01 UTC

    Pure magic, especially this line:

    my $bmp = pack 'a2 V V V l< l< l< v v V V l< l< V V', 'BM', $len + 54, 0, 54, 40, $attrs[1], $attrs[2], 1, 24, $len, 0, +0, 0, 0;

    I tried it immediately but i can't view the file with various image processing software. In some it is simply black, some other reject it.

    Examining the file i get:

    karls-mac-mini:monks karl$ file mandelbrot.bmp mandelbrot.bmp: PC bitmap, Windows 3.x format, 1280 x 1024 x 24

    This looks good, but:

    karls-mac-mini:monks karl$ identify mandelbrot.bmp identify: unrecognized compression `mandelbrot.bmp'.

    Or something is wrong with my GD installation. But i don't think so because the script would complain if something went wrong.

    Thank you very much for advice. Perhaps you have a hint how to continue.

    Best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

      Try this version:

      my $gd = $image->gd; my( undef, $width, $height, undef, undef ) = unpack 'nnnCV', substr( $ +gd, 0, 11, '' ); my $len = length( $gd ) / 4 * 3; my $bmp = pack 'a2 V V V l< l< l< v v V V l< l< V V', 'BM', $len + 54, 0, 54, 40, $width, -$height, 1, 24, 0, $len, 0, 0 +, 0; $bmp .= join'', unpack '(xaaa)*', $gd;

      Looks like I had two fields transposed; even though my image viewer didn't notice (or just didn't look).


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
      In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

        Now i get: identify: Insufficient image data in file `mandelbrot.bmp'.

        «The Crux of the Biscuit is the Apostrophe»

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1129361]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-19 19:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found