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.
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- Upload this image into Drupal and try to process it by any image style.
GIMP (OpenSource image editor)
- Open
image-test.pngin GIMP. - Go to Image | Color Management | Assign Color Profile…
- In Assign section in select element chose Select color profile from disk…
- Select downloaded
.iccprofile. - Click Assign.
- 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.
- 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.
| Comment | File | Size | Author |
|---|
Issue fork drupal-3261924
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
Comment #2
jsidigital commented@someshver
Were you able to fix this?
I still occasionally come across this message ever since I upgraded to php 8.1
Thanks.
Comment #3
jungleThis is a patch to core
Comment #4
jungleUpload 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.
Comment #6
paintingguy commentedI'm getting this on php 8 and most recent upgrade to Drupal core 9.3.12
Comment #7
maxstarkenburgGlad 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/mediaon my local build withstage_file_proxyenabled 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.Comment #8
rakhi soni commentedI 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.
Comment #9
robbdavis commentedExact same problem here as in #8. Warning is from uploading a pdf document as a media item.
Comment #10
devkinetic commentedI 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.
Comment #11
mkindred commentedI'm running into this issue as soon as I view the media library widget in node/x/edit.
Comment #12
wylbur commentedWe 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.
Comment #13
kburakozdemir commentedI can confirm that #8 removes the warning for me.
Drupal version: 9.4.8
PHP version: 8.0.23
Comment #14
gaurav-mathur commentedComment #15
gaurav-mathur commentedI 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.
Comment #16
smustgrave commentedThis 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
Comment #17
jenlamptonI was able to recreate this by uploading a .webp image into an image/media reference field, and then rendering it using an image style.
Comment #18
niklanI 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.
Comment #19
niklanUpdated issue summary with steps to reproduce this problem.
Comment #20
niklanAdded cspell ignore for iCCP
Comment #21
niklanSorry for noise, patch in #20 contains .icc profile by accident. This one is clean patches.
Comment #22
niklanGosh 🤯
Anyway, since I need to create patches again, I generated a test image using
convertinstead of GIMP. It is smaller, because there is no GIMP metadata in it.🤞
Comment #24
chi commentedPersonally, 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.
Comment #25
niklanAdded comment for suppression call.
Disabled tests, because the only difference from #22 is comment.
Comment #26
mudassar774 commentedRe-rolled patch #3 to make it work with 9.5.5
Comment #27
jannakha commented#26 works! no more warning on d 9.5.5/php 8.1.1
thank you!
Comment #28
quietone commentedThe 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?
Comment #29
alex.skrypnykBackporting #8 to D7
Comment #31
neclimdulBetter title.
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?
Comment #32
smustgrave commentedLooking 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.
Comment #33
dieterholvoet commentedRerolled the last patch against 11.x.
Comment #34
mmenavas commentedRerolled the last patch against 10.1.2
Comment #35
ricksta commentedI confirm the patch in 34 works for Drupal 10.
Comment #36
mark_fullmerBased on the comment from #35, I'm changing the status to RTBC.
Comment #37
neclimdulBased 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.
Comment #38
needs-review-queue-bot commentedThe 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.
Comment #44
taran2lComment #45
smustgrave commented1 small feedback item.
Hiding patches for clarity.
Comment #46
taran2l@smustgrave I disagree, the dictionary already has all the wierd words ...
Comment #47
smustgrave commentedWhich is actively trying to be cleaned up
Comment #48
taran2lQuestion: is it possible to resolve threads ?
Comment #49
smustgrave commentedVerified 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.
Comment #50
quietone commentedI'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.
Comment #51
quietone commentedOh sorry, @neclimdul, thank you for answering my question in #31.
Comment #52
wilfred waltman commentedRerolled patch from #34 for Drupal 10.2
Comment #54
taran2lFeedback has been addressed
Also, attaching a static patch from the latest changes in the MR (for composer patching purposes)
Comment #55
smustgrave commentedMR appears to have failures.
Comment #56
taran2lComment #57
smustgrave commentedFeedback appears to have been addressed
Comment #58
nigelcunningham commentedAttaching static version of MR for composer patch.
Comment #59
longwaveThe test doesn't work for me locally. With or without the change to GDToolkit I get:
Not entirely convinced we need the test here, we are only testing PHP's error suppression. The comment is probably good enough?
Comment #60
taran2l@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.
Comment #61
niklanHello 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:
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.
Comment #62
generalredneckIt 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.
Comment #63
neclimdulI 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.
Comment #65
vladimirausResolved MR conflict and added patches for D10 and D11.
Comment #66
ronraney commentedJust curious about Patch 65. What's all the garbage text at the end of the file?
Comment #67
generalredneckThat's a new file... png based on the diff.
Comment #68
vladimirausPull the latest updates into MR.
Comment #71
niklanI 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):
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.pngI 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.
Comment #72
vladimiraus10.3 update
Comment #73
quietone commentedFixes are made on on 11.x (our main development branch) first, and are then back ported as needed according to our policies.
Comment #74
vladimirausComment #75
smustgrave commentedHave not reviewed but MR appears to have errors.
Comment #76
tormiMarked this ticket as possibly related: https://www.drupal.org/project/drupal/issues/3424941#comment-15760118
Comment #77
anybodyConfirming this issue still exists and I agree muting it would make sense, as users can't do anything about it in most cases.
Comment #78
vladimirausComment #79
smustgrave commentedAppears to have test failures.
Comment #80
nitesh624There is one more warning occurring in image system https://www.drupal.org/project/drupal/issues/3474274
Comment #81
nitesh624I am also getting error during test run locally
Comment #82
taran2lGreen again, I think this can go in ?
Comment #83
smustgrave commentedRan test-only feature
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.
Comment #84
nikit commentedWhen will merged?
Comment #85
vladimiraus+1
Comment #86
quietone commentedComment #87
ryrye commentedpatch in #72 no longer works in D10.4.1
Comment #88
catchMR looks good to me, but unfortunately needs a rebase.
Comment #90
weekbeforenextMerged in the latest from origin.
Comment #91
smustgrave commentedRebase seems fine, random javascript error.
Comment #92
catchCommitted/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.
Comment #94
catch