Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 134 lines (103 sloc) 2.677 kb
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
package Imager::File::TIFF;
use strict;
use Imager;
use vars qw($VERSION @ISA);

BEGIN {
  $VERSION = "0.85";

  require XSLoader;
  XSLoader::load('Imager::File::TIFF', $VERSION);
}

Imager->register_reader
  (
   type=>'tiff',
   single =>
   sub {
     my ($im, $io, %hsh) = @_;

     my $allow_incomplete = $hsh{allow_incomplete};
     defined $allow_incomplete or $allow_incomplete = 0;

     my $page = $hsh{page};
     defined $page or $page = 0;
     $im->{IMG} = i_readtiff_wiol($io, $allow_incomplete, $page);

     unless ($im->{IMG}) {
       $im->_set_error(Imager->_error_as_msg);
       return;
     }

     return $im;
   },
   multiple =>
   sub {
     my ($io, %hsh) = @_;

     my @imgs = i_readtiff_multi_wiol($io);
     unless (@imgs) {
       Imager->_set_error(Imager->_error_as_msg);
       return;
     }

     return map bless({ IMG => $_, ERRSTR => undef }, "Imager"), @imgs;
   },
  );

Imager->register_writer
  (
   type=>'tiff',
   single =>
   sub {
     my ($im, $io, %hsh) = @_;

     $im->_set_opts(\%hsh, "i_", $im);
     $im->_set_opts(\%hsh, "tiff_", $im);
     $im->_set_opts(\%hsh, "exif_", $im);

     if (defined $hsh{class} && $hsh{class} eq "fax") {
       my $fax_fine = $hsh{fax_fine};
       defined $fax_fine or $fax_fine = 1;
       if (!i_writetiff_wiol_faxable($im->{IMG}, $io, $fax_fine)) {
$im->{ERRSTR} = Imager->_error_as_msg();
return undef;
       }
     }
     else {
       unless (i_writetiff_wiol($im->{IMG}, $io)) {
$im->_set_error(Imager->_error_as_msg);
return;
       }
     }
     return $im;
   },
   multiple =>
   sub {
     my ($class, $io, $opts, @ims) = @_;

     Imager->_set_opts($opts, "tiff_", @ims);
     Imager->_set_opts($opts, "exif_", @ims);

     my @work = map $_->{IMG}, @ims;
     my $tiff_class = $opts->{class};
     defined $tiff_class or $tiff_class = "";

     my $result;
     if ($tiff_class eq "fax") {
       my $fax_fine = $opts->{fax_fine};
       defined $fax_fine or $fax_fine = 1;
       $result = i_writetiff_multi_wiol_faxable($io, $fax_fine, @work);
     }
     else {
       $result = i_writetiff_multi_wiol($io, @work);
     }
     unless ($result) {
       $class->_set_error($class->_error_as_msg);
       return;
     }

     return 1;
   },
  );

__END__

=head1 NAME

Imager::File::TIFF - read and write TIFF files

=head1 SYNOPSIS

use Imager;

my $img = Imager->new;
$img->read(file=>"foo.tiff")
or die $img->errstr;

$img->write(file => "foo.tif")
or die $img->errstr;

=head1 DESCRIPTION

Imager's TIFF support is documented in L<Imager::Files>.

=head1 AUTHOR

Tony Cook <tonyc@cpan.org>

=head1 SEE ALSO

Imager, Imager::Files.

=cut
Something went wrong with that request. Please try again.