WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 10 months ago

#47840 new enhancement

Weird colors when users upload CMYK JPG images

Reported by: lexo_ch Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version: 5.2.2
Component: Media Keywords: needs-patch
Focuses: ui Cc:

Description (last modified by SergeyBiryukov)

When a user uploads an image which uses the CMYK color spectrum and WordPress applies its magic to the image the colors become very much mixed up.

It would be nice if WordPress would recognize the image format and perhaps convert the CMYK image to an RGB before applying the image optimizations.

How to reproduce the problem?

  1. Go to Gallery (media)
  2. Upload a JPG image which uses the CMYK color spectrum
  3. Watch how e.g. the color green becomes yellow ;)

Attachments (1)

Test CMYK image.jpg (1.5 MB) - added by lexo_ch 2 years ago.
Test CMYK file

Download all attachments as: .zip

Change History (5)

#1 @SergeyBiryukov
2 years ago

  • Component changed from Gallery to Media
  • Description modified (diff)

#2 @Otto42
2 years ago

WordPress doesn't actually have any code to do images on that level, it uses the available libraries already installed on the host, like GD or ImageMagick, to do that grunt work.

So, if something is wrong there, then you need to identify specifically which versions of which libraries are causing the issue. Workarounds might be found, but you'd need to identify them and provide example images that can reproduce the problem.

@lexo_ch
2 years ago

Test CMYK file

#3 @lexo_ch
2 years ago

I uploaded the test image file to multiple wordpress instances on different servers / providers - it always bugs out. Sometimes the guys' shirt is yellow, sometimes the image becomes extremely dark.

#4 @olivM
10 months ago

Imagick has a setColorSpace method that can address this issue

so we could add this in WP_Image_Editor_Imagick class

<?php

class WP_Image_Editor_Imagick extends WP_Image_Editor {

[...]

    /**
     * Sets Image Color Space
     *
     *
     * @param int $colorSpace Color Space
     * @return true|WP_Error True if set successfully; WP_Error on failure.
     */
    public function set_color_space($colorSpace = null)
    {
        if ('image/jpeg' === $this->mime_type) {
            try {
                $this->image->setColorSpace($colorSpace);
            } catch (Exception $e) {
                return new WP_Error('image_color_space_error', $e->getMessage());
            }
        }

        return true;
    }
Note: See TracTickets for help on using tickets.