Using Images

While it is nice to be able to add lines and other shapes to your PDFs, to really add pizzazz, you can incorporate existing images. Using images in PDFs is essentially a three-step process:

1.
Open the image file.
2.
Place the image in the PDF.
3.
Close the image.

In actuality it can be a little more complicated than that once you take into account variable image size and such, but I've got a work-around for that issue, too.

For the most recent versions of PHP, open the image with pdf_open_image_file().

$image_pointer = pdf_open_image_file ($pdf, $format, $image_file); 

Exactly like creating a PDF, you assign a pointer to the open image file. The $format should refer to the format of the image itself: JPEG, GIF, PNG, or TIFF ...

Get PHP Advanced for the World Wide Web: Visual QuickPro Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.