php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71316 libpng warning from imagecreatefromstring
Submitted: 2016-01-08 22:07 UTC Modified: 2021-10-21 16:40 UTC
Votes:24
Avg. Score:3.8 ± 0.9
Reproduced:23 of 23 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (4.3%)
From: humbads at alum dot mit dot edu Assigned: cmb (profile)
Status: Closed Package: GD related
PHP Version: 5.6.17 OS: FreeBSD 10.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: humbads at alum dot mit dot edu
New email:
PHP Version: OS:

 

 [2016-01-08 22:07 UTC] humbads at alum dot mit dot edu
Description:
------------
imagecreatefromstring is writing a warning message to stderr that can not be suppressed by '@' or captured by the error handler.  It should emit a proper PHP warning instead.

I have the following version of libPNG:

php -i | grep -i libpng
libPNG Version => 1.6.19+apng

To run the test script, download the sample PNG image from here:
http://imgbox.com/BzOXLiOr

Note: libPNG 1.5.18 on PHP 5.6.17 for Windows does not have this problem.

Test script:
---------------
php -r '@var_dump(imagecreatefromstring(file_get_contents("1CCHOHSULGF78KW.png")));' 


Expected result:
----------------
resource(6) of type (gd)

Actual result:
--------------
libpng warning: iCCP: known incorrect sRGB profile
resource(6) of type (gd)

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-01-08 22:27 UTC] humbads at alum dot mit dot edu
A workaround is to run the following ImageMagick command on the PNG file before processing:

mogrify -strip 1CCHOHSULGF78KW.png

Source:
http://stackoverflow.com/questions/22745076/libpng-warning-iccp-known-incorrect-srgb-profile
 [2016-01-10 01:48 UTC] pajoye@php.net
-Assigned To: +Assigned To: pajoye
 [2016-01-10 01:48 UTC] pajoye@php.net
Thanks for your report!

Hm. This is a libpng warning.I suppose they move this warning to a simple warning level. 

I will see if we can implement the warning only callback without introducing too much noises:

 png_structp png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn);

only png_error is used now and generates php error.
 [2016-07-17 21:57 UTC] michael dot hartmann at refx dot com
PHP 7.0.8 x64 on Windows. Same problem. Please fix.
 [2016-09-05 09:47 UTC] cmb@php.net
This appears to be a general libgd issue, so I've reported
<https://github.com/libgd/libgd/issues/295> upstream.
 [2017-10-24 07:38 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: pajoye +Assigned To:
 [2018-07-13 08:31 UTC] divinity76+spam at gmail dot com
can reproduce on php 7.1.17 @ ubuntu 17.10  (aka i inconveniently encountered this bug)
 [2018-07-13 09:29 UTC] divinity76 at gmail dot com
can't be captured with ob_start() either, does anybody have a workaround?
 [2020-07-10 10:35 UTC] bugreports2 at gmail dot com
this just sucks wehn you verify that some file is really a png and get spewed by this messages (and no fileinfo is useless given that many errors it makes over years)

libpng warning: Interlace handling should be turned on when using png_read_image
libpng warning: Interlace handling should be turned on when using png_read_image
libpng warning: Interlace handling should be turned on when using png_read_image
libpng warning: Interlace handling should be turned on when using png_read_image
libpng warning: Interlace handling should be turned on when using png_read_image
libpng warning: Interlace handling should be turned on when using png_read_image
libpng warning: Interlace handling should be turned on when using png_read_image
libpng warning: Interlace handling should be turned on when using png_read_image
libpng warning: Interlace handling should be turned on when using png_read_image
libpng warning: Interlace handling should be turned on when using png_read_image
libpng warning: Interlace handling should be turned on when using png_read_image
libpng warning: Interlace handling should be turned on when using png_read_image
libpng warning: Interlace handling should be turned on when using png_read_image
libpng warning: Interlace handling should be turned on when using png_read_image
libpng warning: Interlace handling should be turned on when using png_read_image
libpng warning: Interlace handling should be turned on when using png_read_image
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: CRC error
 [2020-11-04 19:47 UTC] humbads at alum dot mit dot edu
Here is a workaround for the "libpng warning: Interlace handling should be turned on when using png_read_image" warnings emitted to stdout.

$command = "mogrify -interlace none *.png";
exec($command);

Call this prior to calling imagecreatefromstring.
 [2020-11-04 19:50 UTC] rtrtrtrtrt at dfdfdfdf dot dfd
amazing for how many years random shit don't get fixed and no i don't care who and where is resposnible
 [2021-07-23 09:19 UTC] cmb@php.net
> amazing for how many years random shit don't get fixed and no i
> don't care who and where is resposnible

Thanks for your valuable open-source contribution.
 [2021-09-02 06:14 UTC] 2598059791 at qq dot com
$imgInfo = getimagesize($imageFile);
        $img_w = $imgInfo[0];
        $img_h = $imgInfo[1];

        switch ($imgInfo[2]){
            case 1:
                $bgImg =imagecreatefromgif($imageFile);  //gif
                break;
            case 2:
                $bgImg =imagecreatefromjpeg($imageFile); //jpg
                break;
            case 3:
                $bgImg = imagecreatefrompng($imageFile);  //png
                break;
            default:
                die("不支持的图片文件类型");
                exit;
        }
        $fontfile = ROOT_DIR.'/../../Resources/font/simhei.ttf';
        $fontfile = ROOT_DIR.'/font/simhei.ttf';
        if(file_exists($fontfile)){
            echo $imageFile."\n\n";
        }
        $text_color = imagecolorallocatealpha($bgImg,0,0,0,75);
        $pos_x = 30;
        $pos_y = $img_h - 20;
        imagettftext($bgImg, 12, 0, $pos_x, $pos_y, $text_color, $fontfile, '审核药师:');
        $shenhe_img = imagecreatefrompng( ROOT_DIR.'/yaoshi/'.$shenhe );
        $shenheImgInfo = getimagesize( ROOT_DIR.'/yaoshi/'.$shenhe );
        $resize_h = 35;
        $resize_w = intval($shenheImgInfo[0]*$resize_h/$shenheImgInfo[1]);
        $pos_x = 110;
        $pos_y = $img_h-$resize_h-5;
        imagecopyresized($bgImg, $shenhe_img, $pos_x, $pos_y, 0, 0, $resize_w, $resize_h, $shenheImgInfo[0], $shenheImgInfo[1]);
 [2021-10-21 16:40 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2021-10-21 16:40 UTC] cmb@php.net
The upstream issue has been fixed[1]; we have to backport that to
our bundled libgd.

[1] <https://github.com/libgd/libgd/commit/636100b9280a86e70d852d89251fc5492fce33f4>
 [2021-10-26 12:59 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #71316: libpng warning from imagecreatefromstring
On GitHub:  https://github.com/php/php-src/pull/7615
Patch:      https://github.com/php/php-src/pull/7615.patch
 [2021-11-04 10:22 UTC] git@php.net
Automatic comment on behalf of cmb69
Revision: https://github.com/php/php-src/commit/1919c4b44ddd9f056bd53c79c4b99c9e4ce97884
Log: Fix #71316: libpng warning from imagecreatefromstring
 [2021-11-04 10:22 UTC] git@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 07:01:29 2024 UTC