Forum


Replies: 3   Views: 3413
Addimage after imagepng
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 luichanfe  · 14-02-2011 - 21:38

I'm having problems adding images created from the imagepng function, from PHP.
If I edit this same image with an image editor then save and then addImage with the new image it works perfectly. The image created with imagepng function seems to be correct.
Anyone with the same problem?

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

The problem could be that the DPI is not stored in the PNG file. And after you save it in an editor it is saved. 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]

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

Hello,

In the dev version of phpdocx we have fixed that issue related to some images. The next version of phpdocx will solve it.

Regards.