replacePlaceholderImage
- addBackgroundImage
- addFooter
- addFooterSection
- addHeader
- addHeaderSection
- addLineNumbering
- addMacroFromDoc
- addPageBorders
- addProperties
- addSection
- createDocx
- createDocxAndDownload
- createCharacterStyle
- createListStyle
- createParagraphStyle
- createTableStyle
- docxSettings
- embedFont
- importChartStyle
- importHeadersAndFooters
- importListStyle
- importStyles
- modifyPageLayout
- parseStyles
- removeFooters
- removeHeaders
- setBackgroundColor
- setDefaultFont
- setDocumentDefaultStyles
- setEncodeUTF8
- setLanguage
- setMarkAsFinal
- setRTL
- addBibliography
- addBookmark
- addBreak
- addChart
- addCitation
- addComment
- addCrossReference
- addDateAndHour
- addEndnote
- addExternalFile
- addFootnote
- addFormElement
- addHeading
- addImage
- addLink
- addList
- addMathEquation
- addMergeField
- addOLE
- addOnlineVideo
- addPageNumber
- addShape
- addSimpleField
- addSource
- addStructuredDocumentTag
- addSVG
- addTab
- addTable
- addTableContents
- addTableFigures
- addText
- addTextBox
- addWordFragment
- addWordML
- embedHTML
- clearBlocks
- cloneBlock
- deleteBlock
- getTemplateVariables
- getTemplateVariablesType
- modifyInputFields
- modifyMergeFields
- processTemplate
- removeTemplateVariable
- replaceBlock
- replaceListVariable
- replacePlaceholderImage
- replaceTableVariable
- replaceVariableByExternalFile
- replaceVariableByHtml
- replaceVariableByText
- replaceVariableByWordFragment
- replaceVariableByWordML
- setTemplateSymbol
- setTemplateBlockSymbol
- tickCheckboxes
replacePlaceholderImage

Replaces a placeholder within an image by a new image.
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).
variable
The name of the variable that identifies the placeholder image.
src
The path to the image or base64 string or stream to be inserted into the Word document. If a stream is added, use with the streamMode option.
options
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 occurrence of the variable within the Word document. |
replaceShapes | bool | If true, replace images in shapes too. Default as false. |
target | string | Possible values are: document, header, footer, footnote, endnote or comment. |
width | mixed | The value in cm (float) or 'auto' (use image size) or 0 to not change the previous size. |
height | mixed | The value in cm (float) or 'auto' (use image size) or 0 to not change the previous 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, image/bmp). |
resourceMode | bool | If true, uses src as image resource (GD). The image resource is transformed to PNG automatically. Default as false. |
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. |
Image does not exist.
Image format not supported.
getimagesizefromstring not available using streamMode and mime/height/width values are not set.