http://www.perlmonks.org?node_id=1129336


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

->gd is libgd's own internal format. It is unlikely to be recognised by any other graphics libraries or image converters.

It is a very simple format that consists of a 11 byte header (for truecolor) and the X-width * 4 * Y-height bytes of uncompressed image data.

A simple 10x10 (truecolor) image with a diagonal line of colored pixels constructed like this:

$i = GD::Image->new( 10, 10, 1 );; $i->setPixel( $_, $_, $_ ) for 0 .. 9;;

And then output as ->gd and unpacked as bytes :

$x = $i->gd;; print unpack 'C*', $x;;

looks like this (manully formatted):

255 254 ## (A sig of sorts) Low bit of second byte means tr +ue color 0 10 ## Width in pixels 0 10 ## height in pixels 1 ## Indicates no color table (Ie. a non-palette imag +e) 255 255 255 255 ## Seems to be a trailer block 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 ## X x Y x 4 bytes +(U32s) of rgba pixel data 0000 0001 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0002 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0003 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0004 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0005 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0006 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0007 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0008 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0009

It should not be hard to knock up Perl script that converts that to one of the ASCII image formats prevalent on *nix, and then convert that to png.

Note:Palleted images have two extra bytes in the header (not sure about the purpose); a 256 * 4-byte color table following the trailer block; and then width * 1-byte * height image data, where each byte value is an index into the color table.


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