addImage

addImage

BASIC / ADVANCED / PREMIUM

Inserts an image into the Word document.

Description
public addImage ( array $options )

You may use this method to insert images (jpg, gif, png or bmp) into your Word document.

You may easily control:

  • the embedding and positioning of the image within a complex paragraph,
  • the size (if not explicitely given, phpdocx tries to read the width and height from the image headers),
  • the dpi or dots per inch (by default they are taken from the image headers or set to 96 dpi),
  • the scale (default 100%) and
  • the target: main document (default), headers or footers.

Together with some general formatting options.

If one wishes to insert an image within a complex paragraph or a table one should use this method in combination with the addText or the addTable method.

Parameters

options

The possible keys and values are (required options are shown with red background):

key Type Description
src string Path to the image that we want to insert into the Word document.
borderColor string hexadecimal color: FF0000.
borderStyle string Possible values are:
  • solid
  • dot
  • dash
  • lgDash
  • dashDot
  • lgDashDot
  • lgDashDotDot
  • sysDash
  • sysDot
  • sysDashDot
  • sysDashDotDot
borderWidth int Given in emus (1cm = 360000 emus).
caption array
  • 'show_label' (string) show default value Figure,
  • 'text' (string) text of the caption
dpi int Dots per inch.
float string (left, right, center) floating image. It only applies if textWrap is not inline (default value).
height int Image height in pixels.
horizontalOffset int Given in emus (1cm = 360000 emus). Only applies if the image is not floating.
hyperlink string Image link.
imageAlign string Image alignment: right, center,...
scaling int % of size: 50, 100.
spacingTop int Spacing top in pixels.
spacingBottom int Spacing bottom in pixels.
spacingLeft int Spacing left in pixels.
spacingRight int Spacing right in pixels.
target target document (default value), defaultHeader, firstHeader, evenHeader, defaultFooter, firstFooter, evenFooter, comment, endnote or footnote. One should use this parameter in conjuction with the "rawWordML" option to later insert the image in a header or footer.
textWrap int Text wrap:
  • 0 (inline)
  • 1 (square)
  • 2 (front)
  • 3 (back)
  • 4 (top and bottom)
  • 5 (clear)
verticalOffset int Given in emus (1cm = 360000 emus).
width int Image width in pixels.
Return values

Void.

Code samples

Example #1

The resulting Word document looks like:

Example #2

The resulting Word document looks like: