php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81321 incorrect image on save
Submitted: 2021-08-01 21:30 UTC Modified: 2021-08-02 08:36 UTC
From: andrei at anleaf dot com Assigned: cmb (profile)
Status: Not a bug Package: GD related
PHP Version: 7.4.22 OS: CentOs 7.9
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: andrei at anleaf dot com
New email:
PHP Version: OS:

 

 [2021-08-01 21:30 UTC] andrei at anleaf dot com
Description:
------------
problem with opening and saving some png images using imagecreatefrompng() and then save it using imagepng($image,$file).
Image opens OK but when saved, the resulting image has broken alpha channel.
Happens with some png images.

Input image to test is here https://www.dropbox.com/s/c6ne72bobrt2iz9/logo_orig.png?dl=0

Resulting image with problem is here https://www.dropbox.com/s/xs4b4bv6208hiua/logo_new.png?dl=0


Test script:
---------------
$im = imagecreatefrompng("logo_orig.png");
imagepng($im,"logo_new.png");
imagedestroy($im);

Expected result:
----------------
saved image should look the same as an input image

Actual result:
--------------
saved image is completely distorted.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-08-02 08:00 UTC] andrei at anleaf dot com
One more png with the problem
https://www.dropbox.com/s/1kuirhjgvnfcohs/logo_orig-2.png?dl=0

Its conversion result (wrong) is here
https://www.dropbox.com/s/98iklpacpm5ppot/logo-orig-2_new.png?dl=0
 [2021-08-02 08:36 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Package: *Graphics related +Package: GD related -Assigned To: +Assigned To: cmb
 [2021-08-02 08:36 UTC] cmb@php.net
You need to preserve the alpha channel explicitly by calling
imagesavealpha()[1], e.g.

<?php
$im = imagecreatefrompng("orig.png");
imagesavealpha($im, true);
imagepng("new.png");
?>

[1] <https://www.php.net/imagesavealpha>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 15:01:33 2024 UTC