Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICC profiles in PNG images generated by Figma have truncated iCCP chunks #4128

Open
3 of 5 tasks
richhost opened this issue Jun 10, 2024 · 7 comments
Open
3 of 5 tasks
Labels

Comments

@richhost
Copy link

richhost commented Jun 10, 2024

Possible bug

Is this a possible bug in a feature of sharp, unrelated to installation?

  • Running npm install sharp completes without error.
  • Running node -e "require('sharp')" completes without error.

If you cannot confirm both of these, please open an installation issue instead.

Are you using the latest version of sharp?

  • I am using the latest version of sharp as reported by npm view sharp dist-tags.latest.

If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.

If you are using another package which depends on a version of sharp that is not the latest, please open an issue against that package instead.

What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?

Does this problem relate to file caching?

The default behaviour of libvips is to cache input files, which can lead to EBUSY or EPERM errors on Windows.
Use sharp.cache(false) to switch this feature off.

  • Adding sharp.cache(false) does not fix this problem.

Does this problem relate to images appearing to have been rotated by 90 degrees?

Images that contain EXIF Orientation metadata are not auto-oriented. By default, EXIF metadata is removed.

  • To auto-orient pixel values use the parameter-less rotate() operation.

  • To retain EXIF Orientation use keepExif().

  • Using rotate() or keepExif() does not fix this problem.

What are the steps to reproduce?

My operating system is macOS, and I use a display with P3 color.

sharp('img.png').resize({ width: 800 }).toFile("out.png");

What is the expected behaviour?

Keep the original colors.

Please provide sample image(s) that help explain this problem

original image:
img

output image:
out

@lovell lovell added question and removed triage labels Jun 10, 2024
@lovell
Copy link
Owner

lovell commented Jun 10, 2024

My operating system is macOS, and I use a display with P3 color.

The input image contains a P3 ICC profile.

https://sharp.pixelplumbing.com/api-output#keepiccprofile

sharp('img.png')
  .resize({ width: 800 })
  .keepIccProfile()
  .toFile("out.png");

@richhost
Copy link
Author

I tried the above code, but it didn't work.

@lovell
Copy link
Owner

lovell commented Jun 10, 2024

I took a closer look and the compressed iCCP chunk in the sample PNG image you've provided, which is where the PNG format stores ICC profiles, cannot be decompressed via libspng. This means that libspng reports that there is no profile. Here's the output from metadata() for this image - note hasProfile: false.

{
  format: 'png',
  width: 738,
  height: 1758,
  space: 'srgb',
  channels: 4,
  depth: 'uchar',
  density: 216,
  isProgressive: false,
  hasProfile: false,
  hasAlpha: true
}

When using libvips compiled with support for libpng there is an ICC profile available, so my best guess would be that this relates to randy408/libspng#14. Do you know the source of this image? Perhaps the compressed zlib stream within the iCCP chunk is truncated?

Please can you report this issue upstream at https://github.com/randy408/libspng

@lovell lovell changed the title The colors darken ICC profile in PNG image with possibly-invalid iCCP chunk is ingored Jun 10, 2024
@lovell lovell changed the title ICC profile in PNG image with possibly-invalid iCCP chunk is ingored ICC profile in PNG image with possibly-invalid iCCP chunk is ignored Jun 10, 2024
@kleisauke
Copy link
Contributor

The DEFLATE stream within the iCCP chunk appears to be truncated for this particular image, according to both exiftool and https://www.nayuki.io/page/png-file-chunk-inspector.

$ exiftool -icc_profile -b x.png
Warning: Error inflating iCCP - x.png

@lovell
Copy link
Owner

lovell commented Jun 10, 2024

@kleisauke Thanks for confirming my suspicions, I'm not sure how libpng manages to inflate the truncated profile though 🤷

@richhost
Copy link
Author

@lovell Thank you for the information. I exported a PNG image with the P3 Color profile using Figma. In Sharp, it shows hasProfile: false.

image

@lovell
Copy link
Owner

lovell commented Jun 11, 2024

@richhost Thank you, in that case please can you report this to Figma.

@lovell lovell changed the title ICC profile in PNG image with possibly-invalid iCCP chunk is ignored ICC profiles in PNG images generated by Figma have truncated iCCP chunks Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants