Problem/Motivation

When a PNG (and some other rarely used formats) image contains iCCP chunk with sRGB IEC61966-2.1 color profile, libpng triggers warning:

Warning: imagecreatefrompng(): gd-png: libpng warning: iCCP: known incorrect sRGB profile in Drupal\system\Plugin\ImageToolkit\GDToolkit->load() (line 201 of core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php).

This warning is printed for any such image, but they're still valid and displayed correctly.

Steps to reproduce

You need an image with iCCP chunk in it and sRGB IEC61966-2.1 color profile. You can achieve this in several ways.

You can find this color profile in attachments for that issue — sRGB IEC61966-2.1.zip. Extract it first to get .icc profile.

For examples, I will use core/tests/fixtures/files/image-test.png. It will be called image-test.png in commands below without full path.

ImageMagick CLI (convert)

Assuming that color profile (.icc) and image (image-test.png) in the same folder.

  1. convert image-test.png -profile sRGB\ IEC61966-2.1.icc -strip -profile sRGB\ IEC61966-2.1.icc -define png:include-chunk=zTXt,iCCP image-1-icpp.png
  2. Upload this image into Drupal and try to process it by any image style.

GIMP (OpenSource image editor)

  1. Open image-test.png in GIMP.
  2. Go to Image | Color Management | Assign Color Profile…
  3. In Assign section in select element chose Select color profile from disk…
  4. Select downloaded .icc profile.
  5. Click Assign.
  6. Save the image by File | Save as chose name and path and click Export. In open modal window, make sure you have checked Save color profile, and then again Export.
  7. Upload this image into Drupal and try to process it by any image style.

Proposed resolution

Add @ symbol before calling imagecreatefrompng() to suppress this warning.

Issue fork drupal-3261924

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

someshver created an issue. See original summary.

jsidigital’s picture

@someshver

Were you able to fix this?
I still occasionally come across this message ever since I upgraded to php 8.1

Thanks.

jungle’s picture

StatusFileSize
new710 bytes

This is a patch to core

jungle’s picture

Project: Crop API » Drupal core
Version: 8.x-2.x-dev » 10.0.x-dev
Component: Code » image system
Status: Active » Needs review
StatusFileSize
new33.29 KB

Upload an image for reproducing this warning. Meanwhile, I think this should be a core issue. But not sure if it's good to use `@` to ignore warnings in core completely.

Status: Needs review » Needs work

The last submitted patch, 3: 3261924-3.patch, failed testing. View results

paintingguy’s picture

I'm getting this on php 8 and most recent upgrade to Drupal core 9.3.12

maxstarkenburg’s picture

Glad to see I'm not the only one apparently getting this issue. It was hard for me to reproduce (and unlike mentioned above, I wasn't uploading images, though my site is on php 8.0.16), but seems to perhaps happen when certain image style files are being generated (perusing the pages of /admin/content/media on my local build with stage_file_proxy enabled was a good way to generate more instances of the warning).

I'm additionally getting a few instances of Warning: imagecreatefrompng(): gd-png: libpng warning: Interlace handling should be turned on when using png_read_image in Drupal\system\Plugin\ImageToolkit\GDToolkit->load() (line 203 of /var/www/web/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php), which I don't know if that should be its own ticket, but I'm also not entirely sure how to characterize one warning vs. the other. Might not be a hard-and-fast rule, but the latter warning seems to be limited to some (but not all) .png files that clearly started their life as .jpgs as well as some the "generic media" icons, e.g. /sites/default/files/styles/thumbnail/public/media-icons/generic/audio.png.

rakhi soni’s picture

StatusFileSize
new710 bytes

I also got this warning "Warning: imagecreatefrompng(): gd-png: libpng warning: iCCP: known incorrect sRGB profile in Drupal\system\Plugin\ImageToolkit\GDToolkit->load() (line 201 of core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php)." when i was uploading media as a document in pdf form in version 9.5x , so i have created a patch to fix this warning for version 9.5x,, kindly review patch.

robbdavis’s picture

Exact same problem here as in #8. Warning is from uploading a pdf document as a media item.

devkinetic’s picture

Status: Needs work » Needs review

I can confirm this issue on PHP 7.4, latest Drupal 9 and latest libpng. Check out https://stackoverflow.com/questions/22745076/libpng-warning-iccp-known-i... for more details. The patch resolves the warning.

mkindred’s picture

I'm running into this issue as soon as I view the media library widget in node/x/edit.

wylbur’s picture

We were encountering the same error on one of our websites. This was happening on the LIVE site, without stage_file_proxy running.

I tested the patch in comment 8 on a local build, and the warnings stopped.
- drupal core 9.3.22
- php 7.4
- stage_file_proxy enabled

I tested by running the site without, and with all image style derivatives removed. I then loaded pages with images that generated the errors. I could reproduce the errors by deleting all image style derivatives and reloading the pages.

Next I applied the patch and retested with the process above. NO errors were produced.

I've noted the files affected and will test on our production server next.

kburakozdemir’s picture

I can confirm that #8 removes the warning for me.

Drupal version: 9.4.8
PHP version: 8.0.23

gaurav-mathur’s picture

Assigned: Unassigned » gaurav-mathur
gaurav-mathur’s picture

Assigned: gaurav-mathur » Unassigned
StatusFileSize
new28.78 KB
new112.52 KB

I Applied Patch #8 and it working successfully removes the warning for me on Drupal 10.0.x. Adding screenshots to refer after and before patch.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: -imagecreatefrompng +Needs Review Queue Initiative, +Needs steps to reproduce, +Needs tests

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

Could you please provide steps/configuration taken to recreate this.
This will need a test case showing the issue.

Thanks

jenlampton’s picture

I was able to recreate this by uploading a .webp image into an image/media reference field, and then rendering it using an image style.

niklan’s picture

Version: 10.0.x-dev » 10.1.x-dev
Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new9.03 KB
new9.69 KB
new2.74 KB

I was able to extract the broken color profile from the image and apply it to another one and trigger that error in tests. The broken color profile called sRGB IEC61966-2.1. I'm attaching it as well, so you can test it by yourself on any image (by injecting it using CLI tools or image editors like GIMP, Krita, etc).

I'm also switch versions to 10.1.x, because patch from #8 won’t apply on 10.0.x branch. And I focus initially on future branch, if it's needed it can be backported later on.

niklan’s picture

Issue summary: View changes
Issue tags: -Needs steps to reproduce

Updated issue summary with steps to reproduce this problem.

niklan’s picture

StatusFileSize
new9.29 KB
new9.96 KB

Added cspell ignore for iCCP

niklan’s picture

StatusFileSize
new9.06 KB
new9.72 KB

Sorry for noise, patch in #20 contains .icc profile by accident. This one is clean patches.

niklan’s picture

StatusFileSize
new8.43 KB
new9.09 KB

Gosh 🤯

Anyway, since I need to create patches again, I generated a test image using convert instead of GIMP. It is smaller, because there is no GIMP metadata in it.

🤞

The last submitted patch, 22: drupal-3261924-22-test-only.patch, failed testing. View results

chi’s picture

Personally, I would not create tests for suppression operators. Such tests are too tricky.
Also, I think it needs a comment explaining what kind of errors could happen without the suppression.

niklan’s picture

StatusFileSize
new8.43 KB
new9.48 KB
new835 bytes

Added comment for suppression call.

Disabled tests, because the only difference from #22 is comment.

mudassar774’s picture

StatusFileSize
new710 bytes

Re-rolled patch #3 to make it work with 9.5.5

jannakha’s picture

Status: Needs review » Reviewed & tested by the community

#26 works! no more warning on d 9.5.5/php 8.1.1
thank you!

quietone’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work

The issue title is used as the commit message and it should state what this issue resolves instead of being a long error message.

Do we really want to suppress all warnings?

alex.skrypnyk’s picture

Backporting #8 to D7

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

neclimdul’s picture

Title: Warning: imagecreatefrompng(): gd-png: libpng warning: iCCP: known incorrect sRGB profile in Drupal\system\Plugin\ImageToolkit\GDToolkit->load() (line 201 of core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php). » Avoid warning from imagecreatefrompng when loading png with obscure iCCP profiles
Status: Needs work » Needs review

Better title.

Do we really want to suppress all warnings?

I had the same question, but I'm not sure what options we're really given. I suspect this is probably OK though because real problems will throw and exception which gets caught and logged. At least in the 10.x versions of this patch.

That said, the block we're adjusting is generalized for all image formats but the comment clearly only addresses the impact on PNGs. Very bikesheddy but maybe we should probably adjust the documentation to match the scope of the code not the scope of this issue. Something like this?

      // Suppress warnings from image creation because there is a possibility
      // that source images contain data that would trigger non-fatal warnings
      // we can't handle. For example, a PNG saved with 'sRGB IEC61966-2.1'
      // color profile has 'iCCP' chunk data which is not recognized on most
      // systems and will cause libpng to trigger warnings but otherwise do not
      // affect image processing.
smustgrave’s picture

Status: Needs review » Needs work

Looking at #25 and should the test go into ToolkitGdTest?

Also reading the last comment 31 think expanding to match makes sense. Least I can't think of a reason not to.

dieterholvoet’s picture

StatusFileSize
new682 bytes

Rerolled the last patch against 11.x.

mmenavas’s picture

StatusFileSize
new686 bytes

Rerolled the last patch against 10.1.2

ricksta’s picture

I confirm the patch in 34 works for Drupal 10.

mark_fullmer’s picture

Status: Needs work » Reviewed & tested by the community

Based on the comment from #35, I'm changing the status to RTBC.

neclimdul’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new9 KB

Based on the rest of the comments and the lack of tests don't think this is actually ready. There aren't even tests on the last couple patches.

re: #32 what the heck is that test. Its not in the system module, its in the wrong location based on the namespace of the class, the file name doesn't align with the tested class? Something weird going on there but it does look like that's where existing tests are.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new1.85 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

elaman made their first commit to this issue’s fork.

Taran2L changed the visibility of the branch 3261924-avoid-warning-from to hidden.

Taran2L changed the visibility of the branch png-11.x to hidden.

taran2l’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

1 small feedback item.

Hiding patches for clarity.

taran2l’s picture

@smustgrave I disagree, the dictionary already has all the wierd words ...

smustgrave’s picture

Which is actively trying to be cleaned up

taran2l’s picture

Status: Needs work » Needs review

Question: is it possible to resolve threads ?

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
There was 1 error:
1) Drupal\KernelTests\Core\Image\ToolkitGdTest::testIncorrectIccpSrgbProfile with data set "PNG with iCCP profile" ('core/tests/fixtures/files/ima...le.png')
PHPUnit\Framework\Exception: PHP Warning:  imagecreatefrompng(): gd-png: libpng warning: iCCP: known incorrect sRGB profile in /builds/issue/drupal-3261924/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php on line 271
Warning: imagecreatefrompng(): gd-png: libpng warning: iCCP: known incorrect sRGB profile in /builds/issue/drupal-3261924/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php on line 271
/builds/issue/drupal-3261924/vendor/phpunit/phpunit/src/Framework/TestSuite.php:684
/builds/issue/drupal-3261924/vendor/phpunit/phpunit/src/Framework/TestSuite.php:684
/builds/issue/drupal-3261924/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:651
/builds/issue/drupal-3261924/vendor/phpunit/phpunit/src/TextUI/Command.php:144
/builds/issue/drupal-3261924/vendor/phpunit/phpunit/src/TextUI/Command.php:97
ERRORS!
Tests: 97, Assertions: 1197, Errors: 1.

Verified test coverage using test-only feature.

All feedback has been addressed.

@Taran2L as far as threads, as the opener of the thread I use to be able to close myself but that no longer seems to be the case. Think only the person who opened the MR can resolve threads now.

quietone’s picture

Status: Reviewed & tested by the community » Needs work

I'm triaging RTBC issues. I read the IS, the comments and the MR. Thanks for the issue summary. As someone who doesn't work with images it was very clear and easy to understand the problem. I didn't find any unanswered questions.

I read the MR (not a code review) and there is minor work to do on the comments.

quietone’s picture

Oh sorry, @neclimdul, thank you for answering my question in #31.

wilfred waltman’s picture

StatusFileSize
new679 bytes

Rerolled patch from #34 for Drupal 10.2

Taran2L changed the visibility of the branch 10.2.x to hidden.

taran2l’s picture

Status: Needs work » Needs review
StatusFileSize
new9.32 KB

Feedback has been addressed

Also, attaching a static patch from the latest changes in the MR (for composer patching purposes)

smustgrave’s picture

Status: Needs review » Needs work

MR appears to have failures.

taran2l’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Feedback appears to have been addressed

nigelcunningham’s picture

StatusFileSize
new9.32 KB

Attaching static version of MR for composer patch.

longwave’s picture

Status: Reviewed & tested by the community » Needs work

The test doesn't work for me locally. With or without the change to GDToolkit I get:

Testing Drupal\KernelTests\Core\Image\ToolkitGdTest
..E                                                                 3 / 3 (100%)

Time: 00:03.934, Memory: 4.00 MB

There was 1 error:

1) Drupal\KernelTests\Core\Image\ToolkitGdTest::testIncorrectIccpSrgbProfile with data set "PNG with iCCP profile" ('core/tests/fixtures/files/ima...le.png')
PHPUnit\Framework\Exception: libpng warning: iCCP: known incorrect sRGB profile

Not entirely convinced we need the test here, we are only testing PHP's error suppression. The comment is probably good enough?

taran2l’s picture

@longwave this is very weird - it does not work on my local as well ... but it seems it does work on CI, weird

I think the value of the test is that error is being suppressed.

niklan’s picture

Hello again. I see some folks not very happy with silencing all the errors from that call. I understand that as well, it can be helpful sometimes. Without it, I won't be found this issue as well. Maybe we wrap this call $image = @$function($this->getSource()); by a condition?

We have already configuration `system.logging` with `error_level` setting. Maybe we will do it like:

if ($error_level === 'verbose') {
  $image = $function($this->getSource());
}
else {
  $image = @$function($this->getSource());
}

This allows a developer to find out that there is a problem, but it won't be logged and showed on production instances. It might be looking ugly, but it solves most of the concerns here. Currently, as I remember correctly (I've already fixed that images), this will be logged on production on every over page with a broken image when it's processed for the first time (if no style yet created). In some cases, it can create a lot of useless noise in the logging system.

generalredneck’s picture

It IS possible to handle warnings, and therefore forego suppressing them all, but it would require setting up an error handler to do it. That said, if we are worried about particular image profiles, is there a way to whitelist some and check to see if the image is what we want? Is that too process intensive?

Trying to throw some fresh ideas at this that I didn't see in the comments. I do like Niklan's thoughts though.

neclimdul’s picture

I think the concerns might be a bit overstated. Actual problems will trigger real exceptions that get logged. This just avoids warnings that shouldn't be triggered. If I remember correctly they're warnings triggered by the underlying libraries so they don't actually follow PHP's documentation for the method.

VladimirAus made their first commit to this issue’s fork.

vladimiraus’s picture

StatusFileSize
new9.16 KB
new9.4 KB

Resolved MR conflict and added patches for D10 and D11.

ronraney’s picture

Just curious about Patch 65. What's all the garbage text at the end of the file?

generalredneck’s picture

That's a new file... png based on the diff.

diff --git a/core/tests/fixtures/files/image-test-iccp-profile.png b/core/tests/fixtures/files/image-test-iccp-profile.png
new file mode 100644
index 0000000000000000000000000000000000000000..29cb8945f8e4c1ae40de24bf888715e4d870a164
--- /dev/null
+++ b/core/tests/fixtures/files/image-test-iccp-profile.png
@@ -0,0 +1,24 @@
+‰PNG
vladimiraus’s picture

Version: 11.x-dev » 11.0.x-dev

Pull the latest updates into MR.

VladimirAus changed the visibility of the branch 3261924-avoid-warning-from-d11.0 to hidden.

niklan’s picture

I encountered the same issue again, and there was a lot of noise in the logs about it. If you just want to fix images and avoid patching the Drupal core, you can use the following script (adapt it to your needs):

#!/usr/bin/env bash
# Fixes iCCP: known incorrect sRGB profile
cd web/sites/default/files || exit
find . -type f -name '*.png' -exec mogrify \{\} \;

This tool will go through all your PNG images and re-save them with fixes for any issues found. However, it fixes more than just the iCCP profile, so use it with caution. I haven't faced any issues yet.

If you know exactly which images have problems, it's best to run the command directly on those files, like this (you can play with broken files from that issue):

mogrify filename.png

I recommend testing this tool locally before applying it to your live files. Alternatively, you could run the entire process locally and then sync the changes using rsync.

Please note that this command may take some time to complete, because it will open and save each image, regardless of whether it has any issues or not. The more and bigger in size files you have, the slower the process will be.

It utilizes the Mogrify binary provided with the ImageMagick package.

vladimiraus’s picture

StatusFileSize
new9.28 KB

10.3 update

quietone’s picture

Version: 11.0.x-dev » 11.x-dev

Fixes are made on on 11.x (our main development branch) first, and are then back ported as needed according to our policies.

vladimiraus’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Have not reviewed but MR appears to have errors.

tormi’s picture

anybody’s picture

Confirming this issue still exists and I agree muting it would make sense, as users can't do anything about it in most cases.

vladimiraus’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Appears to have test failures.

nitesh624’s picture

There is one more warning occurring in image system https://www.drupal.org/project/drupal/issues/3474274

nitesh624’s picture

I am also getting error during test run locally

PHPUnit\Framework\Exception: PHP Deprecated: image_type_to_extension(): Passing null to parameter #1 ($image_type) of type int is deprecated in web/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php on line 63
taran2l’s picture

Status: Needs work » Needs review

Green again, I think this can go in ?

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Ran test-only feature

1) Drupal\KernelTests\Core\Image\ToolkitGdTest::testIncorrectIccpSrgbProfile with data set "PNG with iCCP profile" ('core/tests/fixtures/files/ima...le.png')
PHPUnit\Framework\Exception: PHP Warning:  imagecreatefrompng(): gd-png: libpng warning: iCCP: known incorrect sRGB profile in /builds/issue/drupal-3261924/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php on line 194
Warning: imagecreatefrompng(): gd-png: libpng warning: iCCP: known incorrect sRGB profile in /builds/issue/drupal-3261924/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php on line 194
ERRORS!
Tests: 96, Assertions: 1185, Errors: 1.
Exiting with EXIT_CODE=2

Shows current coverage.

Hiding the patches so it's clear just the MR, and resolved all threads except the one. Since we are suppressing with '@' not sure a CR would be needed? Will let committer decide that one.

But rest of the feedback appears to be addressed.

nikit’s picture

When will merged?

vladimiraus’s picture

Issue summary: View changes

+1

quietone’s picture

ryrye’s picture

patch in #72 no longer works in D10.4.1

catch’s picture

Status: Reviewed & tested by the community » Needs work

MR looks good to me, but unfortunately needs a rebase.

weekbeforenext made their first commit to this issue’s fork.

weekbeforenext’s picture

Status: Needs work » Needs review

Merged in the latest from origin.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Rebase seems fine, random javascript error.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x, thanks!

Did my best with commit credit but this is a long issue with a lot of commenters on it so apologies if someone was overlooked.

  • catch committed 6f8ecdc2 on 11.x
    Issue #3261924 by taran2l, niklan, vladimiraus, jungle, neclimdul, rakhi...
catch’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.