Graph-Chart
view release on metacpan or search on metacpan
lib/Graph/Chart.pm view on Meta::CPAN
this overwrite the png TAG data with the new value and return the new image
=cut
sub png_zEXt
{
my $self = shift;
my $object = shift;
$self->{ size_tot }->[0] = $self->{ size }->[0] + $self->{ border }->[0] + $self->{ border }->[1];
$self->{ size_tot }->[1] = $self->{ size }->[1] + $self->{ border }->[2] + $self->{ border }->[3];
my $tmp = clone( $self );
# delete $tmp->{ data };
foreach my $idx (0 .. scalar @{$tmp->{ data }})
{
next if ( ! defined $tmp->{ data }[ $idx ] );
delete $tmp->{ data }[ $idx]{ set};
}
delete $tmp->{ img };
my $obj = Data::Serializer->new( 'compress' => 1 );
$object->{ 'Graph::Chart' } = $tmp;
my $tag = $obj->serialize( $object );
my $png_out;
my $ihdr; # IHDR chunk
my %tEXt; # tEXt chunks to insert
my $sig; # PNG signature
my $pos; # position in $png
my $pngsize; # Total size of png
my $text; # 'string' of all tEXt chunks with CRC, etc.
my $tchunk; # content of text chunk
$tEXt{ data } = $tag;
( $sig, $ihdr, $png_out ) = unpack "a8 a25 a*", $self->{ img };
$png_out =~ /(.*)(....PLTE.*)/s;
my $old_tag = $1;
my $end_png = $2;
foreach my $keyword ( keys %tEXt )
{
#* A tEXt chunk contains:
#*
#* Keyword: 1-79 bytes (character string)
#* Null separator: 1 byte
#* Compression method: 1 byte
#* Compressed text: n bytes
my $tbuffer;
$tbuffer = $tEXt{ $keyword };
$tbuffer =~ s/\\([tnrfbae])/control_char($1)/eg;
$tchunk = sprintf "%s%c%s", $keyword, 0, $tbuffer;
$text .= pack "N A* N", ( length( $tchunk ), 'tEXt' . $tchunk, &crc32( 'tEXt' . $tchunk ) );
$pngsize += length( $tchunk ) + 8;
}
$png_out = $sig . $ihdr . $text . $end_png;
$self->{ img } = $png_out;
return $self->{ img };
}
###########################################################################
sub update
{
my $self = shift;
my $object = shift;
# carp Dumper($self);
my $image_gd = GD::Image->new( $self->{img});
# carp $image_gd;
#
# $image->copy($sourceImage,$dstX,$dstY, $srcX,$srcY,$width,$height)
}
###########################################################################
### method to render the Chart ###
###########################################################################
=head2 render
render the chart and return a png image
my $img = $graph->render( \%tag )
the hash ref contain data to put in the PNG meta tag.
the tools img_info.pl allow to see the result.
the tag is serialized in the png
the returned value could be writted in a file like this:
my $png_out = $graph->render();
open( my $IMG, '>', $file ) or die $!;
binmode $IMG;
print $IMG $png_out;
close $IMG;
);
=cut
sub render
{
my $self = shift;
my $object = shift;
my $frame = new GD::Image( $self->{ size }->[0] + $self->{ border }->[0] + $self->{ border }->[1], $self->{ size }->[1] + $self->{ border }->[2] + $self->{ border }->[3] );
my $bg_color = _color_allocate( $self->{ bg_color }, 'ffffffff', $frame );
my $bg_color = _color_allocate( $self->{ bg_color }, 'ffffffff', $frame );
$frame->transparent( $bg_color );
$frame->interlaced( 'true' );
### plot overlay
if ( exists $self->{ overlay } )
{
foreach my $layer ( @{ $self->{ overlay } } )
{
next unless ( ref $layer eq 'HASH' );
my $col_graph;
my $frame_over;
( run in 1.059 second using v1.01-cache-2.11-cpan-e1769b4cff6 )