http://qs1969.pair.com?node_id=11139983


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' );