Replies: 6   Views: 3915
Getting image captions to work?
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by nicks  · 15-01-2016 - 12:02


I've installed the latest release and trying to get to grips with image captions.

I've added a 'caption' parameter as shown below:

$captionsettings = array('text' => 'test');
$image->addImage(array('src' => $imagesrc,'imageAlign' => 'center','height' => $picvar[0],'width' => $picvar[1],'caption' => $captionsettings));


Though I then receive the error:

Fatal error: Call to a member function saveXML() on a non-object in /var/www/phpdocx_corporate-new2/classes/

There is mention of:

'show_label' (string) show default value Figure

I tried setting a value here, though I guess it provides a default?

Is it possible to get demo snippet of how I should declare a caption?



Posted by admin  · 18-01-2016 - 09:04


This a simple sample about how to add image captions:

$options = array(
    'src' => 'image.png',
    'imageAlign' => 'left',
    'scaling' => 50,
    'spacingTop' => 10,
    'spacingBottom' => 0,
    'spacingLeft' => 0,
    'spacingRight' => 20,
    'textWrap' => 0,
    'borderStyle' => 'lgDash',
    'borderWidth' => 6,
    'borderColor' => 'FF0000',
    'caption' => array('show_label' => true, 'text' => 'FIRST IMAGE')


You may read the valid parameters on the addImage API doc (



Posted by nicks  · 20-01-2016 - 12:08

Thanks for the example, however I am not having much luck making it work:

$captionsettings = array('show_label' => true, 'text' => 'FIRST IMAGE');

$image->addImage(array('src' => $imagesrc,'imageAlign' => 'center','height' => $picvar[0],'width' => $picvar[1],'caption' => $captionsettings));


I get this error:

Fatal error: Call to a member function saveXML() on a non-object in /var/www/phpdocx_corporate-new2/classes/ on line 3376


Am I missing any other parameters?

Posted by admin  · 21-01-2016 - 08:30


We've done some checks and everything is working fine, please post the full script. This script must illustrate the issue and be as simple as possible.


Posted by nicks  · 22-01-2016 - 14:04

Sure, I'll email you over an example now.

Posted by jari.heinonen  · 13-04-2016 - 07:04

Hi guys,

It would be quite nice, if one could localize the default label "Figure" of image caption.

Have you any plans to make it possible?

Posted by admin  · 13-04-2016 - 11:41


You could set the option 'show_label' as false and then use 'text' to add a custom string instead of 'Figure'. 'Figure' os a fixed default text added by Word.