NAME
PDF::Make::Image - Image embedding for PDF documents
SYNOPSIS
use PDF::Make::Image;
use PDF::Make::Document;
use PDF::Make::Canvas;
my $doc = PDF::Make::Document->new;
my $page = $doc->add_page(612, 792);
# Load an image
my $img = PDF::Make::Image->from_file('photo.jpg');
# Write image XObject to document
my $obj_num = $img->write_to_doc($doc);
# Register on page
$page->add_image('Im0', $obj_num);
# Draw on canvas
my $canvas = PDF::Make::Canvas->new;
$canvas->image('Im0', 72, 500, 200, 150); # name, x, y, width, height
$page->set_content($canvas->to_bytes);
$doc->to_file('output.pdf');
DESCRIPTION
PDF::Make::Image handles embedding JPEG and PNG images in PDF documents.
JPEG: DCTDecode passthrough (raw JPEG bytes wrapped directly)
PNG: Decompressed, re-encoded with FlateDecode + PNG predictor. Alpha channel emitted as a separate /SMask XObject.
METHODS
from_file($path)
Load an image from a file path. Format auto-detected from magic bytes.
from_bytes($bytes)
Load an image from raw bytes. Format auto-detected.
width, height
Image dimensions in pixels.
format
Image format: 0 = JPEG, 1 = PNG, 2 = Raw.
components
Number of colour components (1=gray, 3=RGB, 4=CMYK).
has_alpha
True if the image has an alpha channel.
write_to_doc($doc)
Write the image as an /Image XObject to the document. Returns the indirect object number.