realityczar has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to create an animated GIF of graphs using GD and GD::Graph. The following code creates individual graph GIF files, but the image.gif that results and is supposed to be the animated version won't open. Where have I gone wrong?
Update: I searched the archives. I read them. And I didn't apply the wisdom. It's a lack of binmode. Sorry to have bothered you.
use strict; use warnings; use GD; use GD::Graph::bars; my $img_width = 288; my $img_height = 216; my $number_of_hours = 24; my $img = GD::Image->new($img_width, $img_height); my $gifdata = $img->gifanimbegin(1,0); foreach my $hour (0..$number_of_hours-1) { my @h = CreateHistogram($hour); my @labels = 0..79; my @data = (\@labels, \@h); my $graph = GD::Graph::bars->new($img_width,$img_height); $graph->set( title => "HISTOGRAM HOUR $hour" ); my $gd = $graph->plot(\@data); $gifdata .= $gd->gifanimadd; open(FIL, ">image_$hour.gif"); binmode FIL; print FIL $gd->gif; close FIL; } $gifdata .= $img->gifanimend; open(GIF,">image.gif"); print GIF $gifdata; close GIF; exit; sub CreateHistogram { # stuff to create a histogram }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem creating animated GIF using GD and GD::Graph
by salva (Canon) on Sep 16, 2014 at 15:04 UTC | |
|
Re: Problem creating animated GIF using GD and GD::Graph
by Anonymous Monk on Sep 16, 2014 at 22:59 UTC |