GD-Cairo
view release on metacpan or search on metacpan
lib/GD/Cairo.pm view on Meta::CPAN
$truecolor = $TRUECOLOR if scalar(@_) == 3;
my $format = $truecolor ? 'argb32' : 'a8';
$format = 'argb32';
my $surface = Cairo::ImageSurface->create( $format, $w, $h );
return $class->newFromSurface( $surface );
}
sub newFromPngData
{
my( $class, $data, $truecolor ) = @_;
pos($data) = 0;
my $surface = Cairo::ImageSurface->create_from_png_stream(sub {
my( $closure, $length ) = @_;
use bytes;
my $buffer = substr($data,pos($data),$length);
pos($data) += $length;
return $buffer;
lib/GD/Cairo.pm view on Meta::CPAN
-1;
}
*setTile = \&setBrush;
sub setBrush
{
my( $self, $image ) = @_;
unless( $image->isa( 'GD::Cairo' ) )
{
$image = GD::Cairo->newFromPngData( $image->png );
}
$self->{brush} = $image;
}
sub setStyle
{
my( $self, @colors ) = @_;
my %lines = $self->_convert_style_to_dashes( @colors );
lib/GD/Cairo.pm view on Meta::CPAN
$self->_fill_shape( $shape, $color );
}
}
sub copy
{
my( $self, $sourceImage, $dstX, $dstY, $srcX, $srcY, $width, $height ) = @_;
unless( $sourceImage->isa( 'GD::Cairo' ) )
{
$sourceImage = GD::Cairo->newFromPngData( $sourceImage->png );
}
push @{$self->{operations}}, [
set_source_surface => [$sourceImage->{surface}, $dstX-$srcX, $dstY-$srcY],
rectangle => [$dstX,$dstY,$width,$height],
fill => []
];
}
*copyResampled = \©Resized;
sub copyResized
{
my( $self, $sourceImage, $dstX, $dstY, $srcX, $srcY, $destW, $destH, $srcW, $srcH ) = @_;
unless( $sourceImage->isa( 'GD::Cairo' ) )
{
$sourceImage = GD::Cairo->newFromPngData( $sourceImage->png );
}
my $scaleX = $destW / $srcW;
my $scaleY = $destH / $srcH;
push @{$self->{operations}}, [
set_source_surface => [$sourceImage->{surface}, 0, 0],
sub {
my( $cr ) = @_;
my $pattern = $cr->get_source;
lib/GD/Cairo.pm view on Meta::CPAN
}
sub copyRotated
{
my( $self, $sourceImage, $dstX, $dstY, $srcX, $srcY, $width, $height, $angle ) = @_;
$angle = $angle/180*PI;
unless( $sourceImage->isa( 'GD::Cairo' ) )
{
$sourceImage = GD::Cairo->newFromPngData( $sourceImage->png );
}
my $w = $sourceImage->width;
my $h = $sourceImage->height;
push @{$self->{operations}}, [
set_source_surface => [$sourceImage->{surface}, 0, 0],
sub {
my( $cr ) = @_;
my $pattern = $cr->get_source;
lib/GD/Cairo.pm view on Meta::CPAN
{
my( $self ) = @_;
$self->_render_operations;
my $buffer = '';
$self->{surface}->write_to_png_stream(sub { $buffer .= $_[1] }, '');
return $buffer;
}
sub writePng
{
my( $self, $filename ) = @_;
open(my $fh, ">", $filename) or die "Error writing to $filename: $!";
binmode($fh);
print $fh $self->png;
close($fh);
}
sub pdf
lib/GD/Cairo.pm view on Meta::CPAN
=over 4
=item new(*FILEHANDLE)
=item new($filename)
=item new($data)
=item newFrom*
(newFromPngData implemented.)
=item colorClosestHWB
=item setAntiAliasedDontBlend($color [,$flag])
=item dashedLine
This is deprecated anyway.
=item fillToBorder
lib/GD/Cairo.pm view on Meta::CPAN
=head1 BUGS
Patches/suggestions are welcome.
=head2 Images are always true colour
I don't think Cairo supports paletted images, see http://cairographics.org/manual/cairo-Image-Surfaces.html#cairo-format-t.
=head2 Alignment in PNG Output
PngSurface doesn't appear to reliably translate coordinates onto the surface e.g. a point at 0,0 doesn't get rendered at all.
=head2 StringFT/String/StringUp
StringFT* will always render using 'Sans-Serif' and String* using 'Monospace' (which depend on fontconfig). I need an example for loading fonts with Cairo.
=head2 SetBrush
GD renders brushes by repeatedly rendering the brush (an image) along the path the given shape provides. This isn't practically achievable with Cairo (AFAIK), so instead I repeat the image along the path/fill.
=head2 SetStyle
t/02-newfrom.t view on Meta::CPAN
#########################
# Insert your test code below, the Test::More module is use()ed here so read
# its man page ( perldoc Test::More ) for help writing this test script.
my $img = GD::Image->new( 400, 300 );
my $black = $img->colorAllocate(0, 0, 0);
my $gdc = GD::Cairo->newFromPngData( $img->png );
ok(1);
t/GD-Cairo.t view on Meta::CPAN
draw_stuff( $gd_image );
my $img = GD::Image->new( $w*2+1, $h, 1 );
my $white = $img->colorAllocate( 255, 255, 255 );
$img->fill(0,0,$white);
$img->setBrush( $gd_image );
$img->setPixel($w/2,$h/2,gdBrushed);
my $cairo_brush = GD::Image->newFromPngData($gd_cairo->png, 1);
$img->setBrush( $cairo_brush );
$img->setPixel($w/2*3+1,$h/2,gdBrushed);
open(my $fh, ">", "examples/rectangle.png") or die $!;
binmode($fh);
print $fh $img->png;
close($fh);
$gd_cairo->writePdf( "examples/test.pdf" );
$gd_cairo->writeSvg( "examples/test.svg" );
( run in 0.398 second using v1.01-cache-2.11-cpan-0a6323c29d9 )