png_embed -- embed a png image into the PDF
int png_embed ( binary string data )
This function is used to insert an external PNG file into the PDF file.
The single parameter data
should contain the raw,
binary PNG data. The function returns a library ID that must be used
to paint the embedded image, or false on error.
Assuming that image.png
is a valid PNG file, the
following code will extract the file data, embed it into the PDF
file, and paint it to a page.
$page = $pdf->new_page("letter"); $fh = fopen("image.png", "r"); $filedata = fread($fh, filesize("image.png")); fclose($fh); $image = $pdf->png_embed($filedata); $placement = $pdf->image_place($image, 10, 10, $page);
This function is really only a convenience wrapper around
->image_raw_embed()
that extracts the necessary data for embedding the image from the png
stream itself.
This function was added in 2.5
Many thanks to Oliver Plathey. This code is heavily derived from his fpdf library (with permission).
The png format has many options available. Only some of these are supported by phppdflib. In particular, images with Indexed or 16 bit color, or with alpha channel are not supported.