Bug #77982 [Asn->Fbk]: Valid PNG file does not resize and outputs a strange error
| From: | cmb@php.net | Date: | Wed, 08 May 2019 07:13:22 +0000 |
| Subject: | Bug #77982 [Asn->Fbk]: Valid PNG file does not resize and outputs a strange error | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-220767@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77982&edit=1
ID: 77982
Updated by: cmb@php.net
Reported by: mark at kreine dot com
Summary: Valid PNG file does not resize and outputs a strange
error
-Status: Assigned
+Status: Feedback
Type: Bug
Package: GD related
Operating System: CentOS 7
PHP Version: 7.3.5
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
The error message is raised by libgd, because
png_create_read_struct() returns NULL to signal failure[1]. A
possible reason for this failure is that the libpng version PHP
has been built against is incompatible with the libpng version
that is used at runtime. Make sure that this is not the case.
[1] <https://github.com/php/php-src/blob/php-7.3.5/ext/gd/libgd/gd_png.c#L154-L162>
Previous Comments:
------------------------------------------------------------------------
[2019-05-07 15:10:05] mark at kreine dot com
Description:
------------
I'm trying to resize a PNG file. Instead of an actual resizing, I can see a very strange error,
which perhaps has nothing to do with my code.
The file that I use is here: https://imgur.com/vjnDpJq
I have myself opened GIMP and draw this, so this cannot be invalid PNG file.
This is the error that's being always reproduced:
[Tue May 07 16:58:42.573572 2019] [php7:warn] [pid 7539:tid 140392702551808] [client
127.0.0.1:42140] PHP Warning: imagecreatefrompng(): gd-png error: cannot allocate libpng main
struct in /var/www/sites/photogallery/index.php on line 7
Here is a configure string, which was used in order to compile PHP:
./configure --prefix=/soft/php --with-apxs2=/soft/httpd/bin/apxs --with-libxml-dir=/soft/libxml
--with-png-dir=/soft/libpng --with-curl=shared,/soft/curl --with-bz2=shared,/soft/bzip
--with-mysqli=shared,/soft/mysql/bin/mysql_config --with-gettext=shared,/soft/gettext
--with-pcre-dir=/soft/pcre --with-jpeg-dir=/soft/libjpeg --with-gd=shared
--with-zlib=shared,/soft/zlib --with-pdo-mysql=shared,/soft/mysql --enable-calendar
--enable-mbstring --enable-bcmath --enable-ftp --enable-zip --enable-soap --enable-exif
--enable-intl --enable-sockets
Test script:
---------------
function resizePng($new_width, $new_height)
{
$file = "/var/www/sites/photogallery/image.png";
$im = imagecreatefrompng($file);
$imnew = imagecreatetruecolor($new_width, $new_height);
imagecopyresized($imnew, $im, 0, 0, 0, 0, $new_width, $new_height, 1920, 1080);
header("Content-type: image/png");
imagepng($imnew);
}
Expected result:
----------------
Resized PNG which is to be outputted in browser.
Actual result:
--------------
An error as follows:
[Tue May 07 16:58:42.573572 2019] [php7:warn] [pid 7539:tid 140392702551808] [client
127.0.0.1:42140] PHP Warning: imagecreatefrompng(): gd-png error: cannot allocate libpng main
struct in /var/www/sites/photogallery/index.php on line 7
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77982&edit=1