Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: How to create and save an image from RGB values

by LanX (Sage)
on Dec 27, 2021 at 23:35 UTC ( #11139960=note: print w/replies, xml ) Need Help??


in reply to How to create and save an image from RGB values

For the records:

We talked about it in the CB and I suggested to create a trivial lossless and uncompressed intermediary raster-image file in a format known to ImageMagick's convert

But I failed to find a sufficiently easy format or a module helping writing it.

Possible candidates are GIF , TIFF , BMP ...

They all require to pack some non-trivial headers.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

update

) to be further converted to a highly compressed format

Replies are listed 'Best First'.
Re^2: How to create and save an image from RGB values
by kikuchiyo (Friar) on Dec 27, 2021 at 23:52 UTC

    How about the PPM format? It's as simple as e.g. "P6 640 480 255\n" followed by the raw RGB binary data. It can be transformed by ImageMagick to any desired format.

    Alternatively, see the write_to_scalar example in Image::PNG::Libpng.

      > How about the PPM format?

      Yeah, that's pretty much what I was imagining (no pun intended ;)

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

Re^2: How to create and save an image from RGB values
by bliako (Monsignor) on Dec 27, 2021 at 23:49 UTC

    Welcome old friend Netpbm / ppm, that's OK but something more efficient (in output file size as well as output file format) is needed. Thanks.

      You didn't say it's such an amount of data, I'm wondering what kind of images you are creating. Charts? Fractals?

      Anyway ... It's been a while since I've worked with convert , but IIRC it's possible to compose bigger pics from smaller ones.

      So you could write out PPM's of small temporary chunks (like stripes of lines) and convert them to your desired compact format and finally glue all parts together.

      update

      ) more importantly, how are you able to keep your RGB array in memory if it's too big for the disk?

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2022-08-10 07:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?