Hi,

On the Mac side, there are library dependencies. I installed extra to cover GIF, PNG, JPEG, and TIFF at least :)

$ brew install giflib libpng libjpeg libtiff freetype $ cpanm Imager -n $ cpanm Imager::File::GIF -n $ cpanm Imager::File::PNG -n $ cpanm Imager::File::JPEG -n $ cpanm Imager::File::TIFF -n $ cpanm Imager::Heatmap -n

Here is the parallel version using MCE::Map.

#!/usr/bin/env perl # https://www.perlmonks.org/?node_id=11104804 # Animated Heatmap # v1. https://www.perlmonks.org/index.pl?node_id=11104262 # v2. https://www.perlmonks.org/index.pl?node_id=11104285 # v3. This; feel free to hack it up and post your version! use strict; use warnings; use Imager; use Imager::Filter::Flines; use Imager::Heatmap; use MCE::Map; # Configuration my $size = { x => 600, y => 60 }; my $japh = 'Just another Perl hacker'; my $filename = 'heatmap_anon_bliako.gif'; # Figure out font my $fontface = $^O eq 'MSWin' ? 'Arial' : $^O eq 'darwin' ? '/System/Library/Fonts/Keyboard.ttf' : '/usr/share/fonts/open-sans/OpenSans-Semibold.ttf'; my $font = $^O eq 'MSWin' ? Imager::Font->new( face => $fontface, size => $size->{x}/12, aa => 1) : Imager::Font->new( file => $fontface, size => $size->{x}/12, aa => 1); STDOUT->autoflush(1); print "Generating GIF frame "; # Create the image my $text = Imager->new(xsize=>$size->{x}, ysize=>$size->{y}); # Generate the text $text->box(color => Imager::Color->new(255, 255, 255), filled => 1); $text->string( font => $font, text => $japh, color => Imager::Color->new('#000000'), x => 1, y => ($size->{x}/12)-1, ); my @insert = (); # Scan image of text for heatmap data for my $x (0..$size->{x}-1) { for my $y (0..$size->{y}-1) { my $pix = ($text->getpixel(x=>$x, y=>$y, type=>'8bit')->rgba())[0] +; push @insert, [ $x, $y, $pix ] } } # Generate, draw and filter the heatmap MCE::Map->init( max_workers => 10, chunk_size => 1, init_relay => '' ); my @data = mce_map { my $x = $_; my $hmap = Imager::Heatmap->new( xsize => $size->{x}, ysize => $size->{y}, xsigma => $x, ysigma => $x, ); $hmap->insert_datas(@insert); $hmap = $hmap->draw; $hmap->filter(type => 'flines'); my $data; $hmap->write(data => \$data, type => 'png'); # calling relay for orderly print output MCE::relay { print "$x " }; $data; } [ 1 .. 10 ]; MCE::Map->finish; print "done!\n"; # Write animated gif Imager->write_multi({ file => $filename, transp => 'none', gif_loop => 0, }, map { Imager->read_multi(data => \$_) } @data); # Isn't perl wonderful? print "Saved $filename\n";

Regards, Mario


In reply to Re^3: Animated Heatmap by marioroy
in thread Animated Heatmap by Anonymous Monk

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.