Forum


Replies: 6   Views: 4240
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/CreateDocx.inc');
$docx = new CreateDocx();

$paramsImg = array(
#'name' => 'http://maps.google.com/maps/api/staticmap?path=color:0xff0000ff|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->addImage($paramsImg);

$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: http://www.aviation-broker.com/typo3conf/ext/payment/res/example_text.docx
Here is the image: http://www.aviation-broker.com/typo3conf/ext/payment/res/staticmap.png

Any suggestions?

http://www.aemka.de/

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 "log4php.properties". You can there insert following code:
[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
[/code]

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

Greetings

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

Hello,

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

Regards.

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?

thanks

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/CreateDocx.inc on line 34[/code]


Here is my source code:

[code]
require('../phpdocx/classes/CreateDocx.inc');
$d = new CreateDocx();
$d->addText('Some Text');
$d->addImage(array('name'=>'../admin-docroot/assets/images/arrow.png'));
$d->createDocxAndDownload('test');
[/code]


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
Aaron

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]http://www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html#C.pHYs[/url]) so the PHPDOCX code should be aware of that. I mad a quick fix for the function getDpiPng in classes/CreateImage.inc:


[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));
fclose($a);
$x = substr($data, 0, 8);
$y = substr($data, 8, 8);
return array(hexdec($x), hexdec($y));
}[/code]