Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

This works for me. I have used Image::PNG::Libpng. Somehow last night, in the dark, it looked scary but in the light of day it turns out to be quite adorable. And fast too.

use Image::PNG::Libpng ':all'; use Image::PNG::Const ':all'; my $W = 500; my $H = 500; my $compression_level = 9; ################################# my %ihdr = ( width => $W, height => $H, bit_depth => 8, # one of: PNG_COLOR_TYPE_GRAY, PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLO +R_TYPE_PALETTE, PNG_COLOR_TYPE_RGB, PNG_COLOR_TYPE_RGB_ALPHA. color_type => PNG_COLOR_TYPE_RGB, ); my @rows; for my $y (0..$H-1){ # each row is a binary string packing $W (R,G,B) triplets (not + an array) # so we keep appending to this binary buffer (a string! but bi +nary string ok,right?) my $col_bin_str = ""; for my $x (0..$W-1){ my $R = int(rand()*0x100); my $G = int(rand()*0x100); my $B = int(rand()*0x100); # test compression with this "compressable" content # my ($R, $G, $B) = (0xFF) x 3; # pack an R,G,B tripplet into 3 bytes, each an unsingned char # that would be different for different scheme (RGBA) +etc. $col_bin_str .= pack "CCC", $R, $G, $B; } push @rows, $col_bin_str; } my $png = create_writer('file.png'); $png->set_compression_level($compression_level); $png->set_IHDR(\%ihdr); $png->set_rows(\@rows); $png->write_png();

bw, bliako


In reply to Re: How to create and save an image from RGB values by bliako
in thread How to create and save an image from RGB values by bliako

Title:
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 janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-03-28 21:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found