Replaces a placeholder within a image by a new image.

public replacePlaceholderImage (string $variable, string $src[, array $options])

This method allows to replace a placeholder image that may be fully formatted in Word (border, shadows, effects...) by an image of our choice.

If one does not set the width, height and/or dpi options the method will use the corresponding data taken from the original placeholder image.

The placeholder image should be tagged using the alternate text option of your Word interface (this may depend on your Word version).



The name of the variable that identifies the placeholder image.


The path to the image or stream that you want to insert into the Word document. If a stream is added use with the streamMode option.


The possible keys and values of this array are:

Key Type Description
firstMatch boolean If the variable appears more than once within the Word document and firstMatch is set to true, phpdocx will only replace the first ocurrence of the variable within the Word document.
target string Possible values are: document, header, footer, footnote, endnote or comment.
width mixed The value in cm (float) or 'auto' (use image size).
height mixed The value in cm (float) or 'auto' (use image size).
dpi int Dots per inch. This parameter is only taken into account if width or height are set to auto.
mime string Forces a mime (image/jpg, image/jpeg, image/png, image/gif)
streamMode bool If true, uses src as stream. PHP 5.4 or greater needed to autodetect the mime type; otherwise set it using mime option. Default is false.
Return values


Code samples

Example #1

The resulting Word document looks like:

Example #2