G'day bliako,

"Ideally, I would like a method which just takes in an array of RGB values and creates the image (fastly)."

The following Tk code does this.

#!/usr/bin/env perl use strict; use warnings; use Tk; use Tk::PNG; use Time::HiRes 'time'; my $mw = MainWindow::->new(); my @common_raw_rgbs; my $png_image = 'pm_11139959_image.png'; my ($W, $H) = (100, 100); { no warnings 'qw'; @common_raw_rgbs = qw{ #ff0000 #ffff00 #009900 #00ffff #0000ff #ff00ff }; } my @raw_rgbs = (@common_raw_rgbs) x int(1 + ($W * $H / (0+@common_raw_ +rgbs))); my $t0 = time; my $image = $mw->Photo(-format => 'png', -width => $W, -height => $H); my $i = 0; for my $y (0 .. $H - 1) { for my $x (0 .. $W - 1) { $image->put([$raw_rgbs[$i++]], -to => $x, $y, $x + 1, $y + 1); } } $image->write($png_image); my $t1 = time; $mw->Label(-text => 'Image:')->pack(); $mw->Label(-image => $image)->pack(); $mw->Label(-text => 'Time: ' . sprintf '%.6f', $t1 - $t0)->pack(); MainLoop;

Notes:

— Ken


In reply to Re: How to create and save an image from RGB values [Tk in ~0.059s] by kcott
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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.