Hi guys!
So, a big problem now, really, it’s very complicated problem.
After I open and optimize a PNG image using Aspose Java Imaging, if I try open this saved image in PHP using GD2 library, an error is occurs. This saved image open correct at any image viewers like Photoshop, Mac OSx Image Preview, Windows Image Viewers and others image editor and previews.
The PHP GD2 library use the libpng (http://www.libpng.org). If I open this saved image using libpng, the error has been returned “Extra compressed data”. The extra compressed data is extra space containeds at image content, may otherwise be used as a Trojan Horse.
Libpng C Code:
For simulate the problem, these steps are required.
1. Use Aspose Java Imaging to open, modify and save the PNG image file:
String path = new File(“.”).getCanonicalPath() + “\images\”;
PngImage image = new PngImage((path + “original.png”));
PngOptions options = new PngOptions();
image.setTransparentColor(Color.getTransparent());
image.setTransparentColor(true);
options.setColorType(PngColorType.TruecolorWithAlpha);
options.setCompressionLevel(5);
options.setFilterType(PngFilterType.Adaptive);
image.save((path + “compacted.png”), options);
image.close();
2. Open the PNG image file saved at PHP (5.2, 5.4, 5.6 or anything):
<span style=“font-family: “Courier New”; font-size: small;”>$content = file_get_contents(‘compacted.png’);
<div style=“font-size: small; font-family: “Courier New”;”>$resource = imagecreatefromstring($content);
<div style=“font-size: small; font-family: “Courier New”;”>imagepng($resource, null, 0);<div style=“font-size: small; font-family: “Courier New”;”>imagedestroy($resource);<div style=“font-size: small; font-family: “Courier New”; font-style: italic;”><div style=“font-size: small; font-family: “Courier New”; font-style: italic;”>And vuola! The error is occurs on the PHP:<div style=“font-size: small; font-family: “Courier New”;”>exception ‘PhpInternalException’ with message '[Warning] imagecreatefromstring(): gd-png: fatal libpng error: Extra compressed data.<div style=“font-size: small; font-family: “Courier New”;”>
<div style=“font-size: small; font-family: “Courier New”;”>But look now, this is the best part of the problem. This error is not occurs with all PNG image files, only with a few files. This image is a example that occurs:<div style=“font-size: small; font-family: “Courier New”;”>https://drive.google.com/open?id=0B0mpguk3CYW0dEh1dHZrVkwtbnc<div style=“font-size: small; font-family: “Courier New”;”>
Well, this is my problem now. Any ideas about this?