php / php/php-src

Suppress Warnings From libpng

Open
#23,674 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Extension: gd Feature Good first issue Status: Needs Triage
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.