in reply to How to create and save an image from RGB values
I think Imager is good enough for this task. Though starting point looks strange to me, but assuming there already is, as in OP, a Perl array of (unusual) ARGB packed colour values, read the 4 channels, then just drop useless 0th channel. Otherwise the hassle with "combine" (or something similar, TMTOWTDI), etc. is unnecessary, of course.
use strict; use warnings; use Imager; use constant IMAGESIZE => 300; use constant ROSYBROWN => 0x00BC8F8F; my @result = map { # make us some picture to find when ( ROSYBROWN ) x $_, # examining output, let it be random int( rand 0xFFFFFFFF ), # colour diagonal on uniform BG ( ROSYBROWN ) x ( IMAGESIZE - $_ - 1 ), } 0 .. IMAGESIZE - 1; my $img = Imager-> new( type => 'raw', xsize => IMAGESIZE, ysize => IMAGESIZE, data => pack( 'L>*', @result ), raw_interleave => 0, raw_datachannels => 4, raw_storechannels => 4, ); Imager-> combine( src => [ $img, $img, $img ], channels => [ 1, 2, 3 ], )-> write( file => 'test.png' );
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How to create and save an image from RGB values
by bliako (Monsignor) on Dec 28, 2021 at 13:02 UTC | |
by vr (Curate) on Dec 28, 2021 at 13:49 UTC | |
by etj (Deacon) on Dec 31, 2021 at 00:57 UTC | |
by vr (Curate) on Jan 02, 2022 at 11:41 UTC | |
by syphilis (Archbishop) on Jan 02, 2022 at 13:06 UTC | |
| |
by Anonymous Monk on Jan 03, 2022 at 11:33 UTC | |
by bliako (Monsignor) on Dec 28, 2021 at 15:12 UTC |
In Section
Seekers of Perl Wisdom