1use Test::More tests => 7;
2
3use warnings;
4use strict;
5
6use PDF::API2;
7
8# Filename
9
10my $pdf = PDF::API2->new();
11$pdf->{forcecompress} = 0;
12
13my $png = $pdf->image_png('t/resources/1x1.png');
14isa_ok($png, 'PDF::API2::Resource::XObject::Image::PNG',
15       q{$pdf->image_png(filename)});
16
17is($png->width(), 1,
18   q{Image from filename has a width});
19
20my $gfx = $pdf->page->gfx();
21$gfx->image($png, 72, 144, 216, 288);
22like($pdf->stringify(), qr/q 216 0 0 288 72 144 cm \S+ Do Q/,
23     q{Add PNG to PDF});
24
25# Large RGBA PNG file
26
27$pdf = PDF::API2->new();
28
29$png = $pdf->image_png('t/resources/test-rgba.png');
30isa_ok($png, 'PDF::API2::Resource::XObject::Image::PNG',
31       q{$pdf->image_png(filename)});
32
33# Filehandle
34
35$pdf = PDF::API2->new();
36open my $fh, '<', 't/resources/1x1.png';
37$png = $pdf->image_png($fh);
38isa_ok($png, 'PDF::API2::Resource::XObject::Image::PNG',
39       q{$pdf->image_png(filehandle)});
40
41is($png->width(), 1,
42   q{Image from filehandle has a width});
43
44close $fh;
45
46# Missing file
47
48$pdf = PDF::API2->new();
49eval { $pdf->image_png('t/resources/this.file.does.not.exist') };
50ok($@, q{Fail fast if the requested file doesn't exist});
51