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?


In reply to Image modules not returning or accepting GD::Image by Bod

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.