Name

png_embed -- embed a png image into the PDF

Synopsis

int png_embed ( binary string data )

Description

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.

Examples

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);

See Also

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.

History

This function was added in 2.5

Many thanks to Oliver Plathey. This code is heavily derived from his fpdf library (with permission).

Bugs

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.