[cairo-commit] cairo-perl/examples png-streams.pl,NONE,1.1
Torsten Schoenfeld
commit at pdx.freedesktop.org
Fri Aug 11 11:51:48 PDT 2006
Committed by: tsch
Update of /cvs/cairo/cairo-perl/examples
In directory kemper:/tmp/cvs-serv9926/examples
Added Files:
png-streams.pl
Log Message:
* examples/png-streams.pl: New example that demonstrates how to
use the PNG stream functions.
* t/CairoSurface.t: Whitespace fix.
--- NEW FILE: png-streams.pl ---
#!/usr/bin/perl
# $Id: png-streams.pl,v 1.1 2006/08/11 18:51:46 tsch Exp $
use strict;
use warnings;
use Cairo;
my $filename = $ARGV[0];
unless (-e $filename && -f $filename) {
die "`$filename´ doesn't seem to be a file";
}
open my $rfh, '<', $filename;
my $surface = Cairo::ImageSurface->create_from_png_stream (sub {
my ($closure, $length) = @_;
my $buffer;
if ($length != sysread ($rfh, $buffer, $length)) {
die 'read-error';
}
return $buffer;
});
warn "status: " . $surface->status;
close $rfh;
open my $wfh, '>', $filename . '.bak';
$surface->write_to_png_stream (sub {
my ($closure, $data) = @_;
if (!syswrite ($wfh, $data)) {
die 'write-error';
}
});
close $wfh;
warn "status: " . $surface->status;
More information about the cairo-commit
mailing list