addImage

addImage

BASIC / ADVANCED / PREMIUM

Inserts an image into the PowerPoint presentation.

Description
public addImage($image, $position, $imageStyles = array(), $options = array())

This method inserts images (png, jpg, jpeg, gif, bmp, webp) into the PowerPoint presentation.

Parameters

image

Image path, base64, stream or GdImage.

position

Key Type Description
coordinateX int EMUs (English Metric Unit).
coordinateY int EMUs (English Metric Unit).
sizeX int EMUs (English Metric Unit).
sizeY int EMUs (English Metric Unit).
name string Internal name. If not set, a random name is generated.
order int Set the display order. Default after existing contents. 0 is the first order position. If the order position doesn't exist add after existing contents.

imageStyles

Key Type Description
border array
  • 'dash' (string) solid, dot, dash, lgDash, dashDot, lgDashDot, lgDashDotDot, sysDash, sysDot, sysDashDot, sysDashDotDot.
  • 'color' (string) default as 000000.
  • 'width' (int) EMUs (English Metric Unit). Default as 12700 (1pt).
descr string Descr value.
hyperlink string Hyperlink: external, bookmark (#firstslide, #lastslide, #nextslide, #previousslide) or slide (#slide + position).
rotation int 60.000ths of a degree.
transparency int 0 to 100.

options

Key Type Description
mime string Forces a mime (image/jpg, image/jpeg, image/png, image/gif, image/bmp, image/webp).
Exceptions

Image doesn't exist.

Image format is not supported.

Mime option is not set and getimagesizefromstring is not available.

Size not valid.

Hyperlink slide position not valid.

Position not valid.

Code samples

Example #1

The resulting PPTX looks like:

Release notes
  • phppptx 4.5:
    • transparency option.
    • rotation uses 60.000ths of a degree.
  • phppptx 4.0:
    • removed PHP Warnings when images to be added do not exist.
  • phppptx 3.0:
    • WebP images.
    • GdImage as image source.
  • phppptx 1.0:
    • new method.