Bod has asked for the wisdom of the Perl Monks concerning the following question:
At first I thought I had simply found an error in the documentation. But as I seem to have found two related errors in two different modules, I am questioning either my understanding or if I am overlooking something silly.
I'm trying to put three images side by side into a PDF. As I don't know the dimensions of the images, I am using Image::Resize to set them all to the same height. This bit works fine. Then I am using GD::Tiler to stitch them together into a single image before using PDF::API2 to add the images to the PDF.
The documentation for GD::Tiler says that it returns a GD::Image object. But it doesn't - it returns an image. PNG by default. I've confirmed this with $test = 1; in the code sample below. I've also looked at the source code which confirms that the documentation is wrong.
So I've made a new GD::Image object from the PNG as PDF::API2 says that the image method takes a GD::Image object. I have confirmed that we have the right object type using $test = 2; in the code sample below.
However, when I pass the GD::Image object to $pdf->image I get this error:
Not a HASH reference at /home/shoples1/perl5/lib/perl5/PDF/API2.pm line 2359
Here is some test code to demonstrate the problem.
#!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser); use strict; use warnings; use lib "$ENV{'DOCUMENT_ROOT'}/../lib"; use cPanelUserConfig; use PDF::API2; use GD::Tiler qw(tile); my $test = 0; my $pdf = PDF::API2->open("$ENV{'DOCUMENT_ROOT'}/../data/Consent.pdf" +); my $page = $pdf->open_page(1); my @image = ( "$ENV{'DOCUMENT_ROOT'}/images/admin/dogs/boomer.jpg", "$ENV{'DOCUMENT_ROOT'}/images/admin/dogs/1.jpg", "$ENV{'DOCUMENT_ROOT'}/images/admin/dogs/2.jpg", ); my $gd = tile( Images => \@image, Center => 1, ImagesPerRow => 3, ); # GD::Tiler is returning a PNG not a GD::Image object my $image = GD::Image->new($gd); if ($test == 1) { print "Content-type: image/png\n\n"; print $gd; exit; } if ($test == 2) { use Scalar::Util qw(blessed reftype); print "Content-type: text/plain\n\n"; print blessed($image); # GD::Imaage exit; } my $dogs = $pdf->image($image); # FAILS HERE $page->object($dogs, 1000 - $gd->width / 2, 100, 100); $pdf->save("$ENV{'DOCUMENT_ROOT'}/test.pdf"); print "Location: /test.pdf\n\n"; exit;
I've tried looking at the source for PDF::API2 but that part is beyond me. The image method works with a filepath but not with a GD::Image. I've not tried using a filehandle.
Have I found two separate modules with documentation errors around GD::Image or have I missed something obvious here?
|
|---|