Replies: 6   Views: 1980
Addimage null error
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 CarlEOgden  · 05-03-2020 - 16:47

Deleted by CarlEOgden · 05-03-2020 - 18:52

Posted by admin  · 05-03-2020 - 17:19


That error doesn't seem from phpdocx but from the code you are running. As you can check in the error you get:

Call to a member function addImage() on null

This line means that when calling:


$rooms_image is null, not a CreateDocx/CreateDocxFromTemplate object, so you get an error because you can't call addImage from null. We recommend you to check how you are creating the $rooms_image object.


Posted by CarlEOgden  · 05-03-2020 - 18:02


Thanks for the reply, all the variables are set properly and populated but for some reason on some photos, and this is the main issue, we get a null error - but it's something happening within createDocx / addImage.

I think I will have to examine a photo from a non-working call and a working call!

Cheers for now

Posted by admin  · 05-03-2020 - 18:25


If the script returns:

Call to a member function addImage() on null

then $rooms_image in $rooms_image->addImage($image_options); is null, not a CreateDocx/CreateDocxFromTemplate instance. And also, as we can check in the output sent, the error appears in the script you are running:

Call to a member function addImage() on null


If an exception or error is returned by phpdocx, then a phpdocx class appears, not an external script (BrochureHelpers.php).

Maybe your code has a conditional that generates a correct CreateDocx object based on the image (or other condition) and in some cases, the object is not being generated correctly?

phpdocx doesn't throw a null error if an image can't be added, it returns an image error exception.

We recommend you to run the included samples and test addImage standalone with the same images:, so you can find the source of the problem.


Posted by CarlEOgden  · 05-03-2020 - 18:38


Thanks for the info, I've just captured what we are sending to cause this routine to crash and the variables and their values are:

src = ...vhubl-a54be1def8bed4834ed3212e2683a959.jpg
Photo Width = 2048
Photo Height = 1366
height = 197
width = 295
textWrap = 0
imageAlign = left
spacingTop = 0
spacingLeft = 0
spacingRight = 0
spacingBottom = 8

This 'src' file is there (I've done a file_exists() prior to the call and will only work if it does! I've removed some of the url for security reasons!

Also, the variables above "Photo Width/Photo Height" are from the actual photo.

Any ideas if the addImage routine extracts any info from the image?


Posted by admin  · 05-03-2020 - 20:24


phpdocx extracts dpi information from the image if it's not set using the dpi option, and also its size and mime (getimagesize).

Please also note that file_exists PHP function may fail when using an URL:

If you send the image to contact[at] the image, we'll test it using addImage with the same options you are using.


Posted by CarlEOgden  · 06-03-2020 - 08:54

Hi Admin

Thanks for your assistance, it turned out (as I have replaced the previous programmer) that the routine was bug ridden and would of never worked. I've sorted it out and is now working okay.

Once again, thank you as I needed a kick back into my brochurehelpers code and then spotted the mistakes!