-
Notifications
You must be signed in to change notification settings - Fork 21
Description
To include an image in a PDF document, PDF::API2 provides the method image
:
$img = $pdf->image( $file, %options );
where $file
may be either a file name, a filehandle, or a GD::Image
object.
In a number of situations the calling program provides the image data itself, or has the image file already read into a scalar variable. To pass this data to the image
method we need a temporary file, or 'wrap' it in a file handle:
open( my $fh, '<:raw', \$data );
$img = $pdf->image( $fh, %options );
This works most of the time, but crashes Image::PNG::Libpng
.
Although it is not very hard to augment image
to (also) take scalar data as its first argument I think it is better to add a new method, image_from_scalar
.
$img = $pdf->image_from_scalar( $data, %options );
This will allow PDF::API2 and calling programs to take advantage of file data in scalars without the need to use temporary files or faked file handles.
If you agree I offer to make a PR.
EDIT: $font = $pdf->font($file)
is another good candidate for a font_from_scalar
sibling.