File: png-streams.pl

package info (click to toggle)
libcairo-perl 1.070-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 560 kB
  • ctags: 699
  • sloc: perl: 2,278; ansic: 71; makefile: 4
file content (42 lines) | stat: -rw-r--r-- 693 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/perl

# $Id$

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;