Suppress Warnings From libpng
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
PNG files exported from some applications, most notably Photoshop, are written with an sRGB profile that libpng sees as invalid. Any attempt to load a file like this using the GD library causes a warning to be written to the PHP error log. It is not possible to suppress this warning.
The following code:
<?php
$image = imagecreatefrompng('clouds.png');
Results in this warning:
Warning: imagecreatefrompng(): gd-png: libpng warning: iCCP: known incorrect sRGB profile
Please see the attached file as an example of one that has the issue.
The only solution I have found so far is to post-process the PNG to remove the sRGB profile. This is not ideal for workflow with large numbers of files. Whilst it is possible to disable all warnings, they are often on in production so this is not a desirable solution.
I would like a method to suppress all libpng warnings. This could be implemented as a gd_ prefixed method that takes an optional bool parameter to toggle warnings on or off. If no parameter is passed it could return the current state.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the GD implementation behind imagecreatefrompng and its libpng warning handling. Check how the existing PHP GD API exposes image-loading behavior and whether related tests cover warnings. Done means providing the requested way to toggle libpng warnings, including the optional state query, with coverage for the provided invalid-profile case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, php
- Domain
- computer-graphics
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100