Replies: 6   Views: 4228
Addimage not doing anything
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 aemka  · 11-05-2011 - 12:53

Hi Forum,

I'm just giving the free version of phpdocx a first try. First problem I encountered was, that addImage does not seem to work. So far I did the following:

require_once (PATH_site . 'typo3conf/ext/payment/lib/phpdocx/classes/');
$docx = new CreateDocx();

$paramsImg = array(
#'name' => '|weight:5|40.737102,-73.990318|40.749825,-73.987963|40.752946,-73.987384|40.755823,-73.986397&size=512x512&sensor=false',
#'name' => PATH_site . 'typo3conf/ext/payment/res/staticmap.png',
'name' => '../../typo3conf/ext/payment/res/staticmap.png',
'scaling' => 50,
'spacingTop' => 0,
'spacingBottom' => 0,
'spacingLeft' => 0,
'spacingRight' => 0,
'textWrap' => 1,
'border' => 0,
'borderDiscontinuous' => 1,

$docx->createDocx(PATH_site . 'typo3conf/ext/payment/res/example_text');

The path to the image is right in all above versions. (is_readable() says TRUE)
I tried the URL - result php dies with no error shown even though display_errors is on and error_reporting is at E_ALL.
I tried the absolute path - no image inserted.
I tried the relative path - no image inserted.

Here is the output:
Here is the image:

Any suggestions?

Posted by naoki.peter  · 11-04-2013 - 12:12

Hi aemka

Did you try to enable the log - tool for phpdocx?

Navigate to the phpdocx folder, open "classes/conf" and edit the file "". You can there insert following code:
#log4php.rootLogger = WARN, phpdocx_error

#log4php.appender.phpdocx_error = LoggerAppenderConsole
#log4php.appender.phpdocx_error.layout = LoggerLayoutPattern
#log4php.appender.phpdocx_error.layout.ConversionPattern = %d %p - %m%n

log4php.rootLogger = DEBUG, phpdocx_error

log4php.appender.phpdocx_error = LoggerAppenderRollingFile
log4php.appender.phpdocx_error.file = /tmp/phpdocx.log
log4php.appender.phpdocx_error.layout = LoggerLayoutTTCC
log4php.appender.phpdocx_error.MaxFileSize = 2MB
log4php.appender.phpdocx_error.MaxBackupIndex = 3

After you call your script, it should write stuff in the logfile "/tmp/phpdocx.log". Perhaps there you find more information about the problem.


Posted by admin  · 11-04-2013 - 12:12


Filepath seems wrong. Check if the image exists and activate LOG error to get more info.


Posted by patte  · 11-04-2013 - 12:12

I'm getting the same error - i can add text and create a doc but when i try add an image the script just fails without no warning, i've enabled error logs and i just keep getting the message of image does not exist, i have tried to add the image path in a lot of different way (relative and absolute) and i echo out the image name before adding it which is correct so i dont know why i keep getting this error. Very frustrating

I'm using the trial version and would need the full version once i can sort this out. I'm using the phpdocx as part of a wordpress plugin written in classes but that shouldn't make any difference to the file url should it? Also are you able to add images from different domain url's?


Posted by mathanasoulis  · 11-04-2013 - 12:12

I am having the same issue. Further, when I enable logging, I get this error:

[code]Fatal error: Cannot redeclare class CreateDocx in [...]/phpdocx/classes/ on line 34[/code]

Here is my source code:

$d = new CreateDocx();
$d->addText('Some Text');

With logging disabled, I am given a file to download but it contains all the html on the originating page, and does NOT contain the text "Some Text".

Thanks for any help you can provide

Posted by oqapi  · 11-04-2013 - 12:12

The problem could be that the DPI is not stored in the PNG file. The DPI is not mandatory in PNG ([url][/url]) so the PHPDOCX code should be aware of that. I mad a quick fix for the function getDpiPng in classes/

[code] private function getDpiPng($filename)
// open the file and read first 20 bytes.
$a = fopen($filename, 'r');
$string = fread($a, 1000);
$aux = strpos($string, 'pHYs');
//some png files do not have the pHYs, so we return a default
if ($aux === FALSE) return array(2835,2835);
$data = bin2hex(substr($string, $aux + strlen('pHYs'), 16));
$x = substr($data, 0, 8);
$y = substr($data, 8, 8);
return array(hexdec($x), hexdec($y));