how can i test a jpg image for cmyk or rgb color mode in wordpress/php?

image, jpeg, php, wordpress

Solution

You can use `getimagesize()`. http://php.net/manual/en/function.getimagesize.php

$imgDetails = getimagesize('yourimage.jpg');
if ($imgDetails['channels'] === 4) {
    // CMYK
} elseif ($imgDetails['channels'] === 3) {
    // RGB
}

Problem

I just had a client upload a jpg image in CMYK and it wasn't rendering correctly in IE and some versions of firefox. Is there a check I can do to make sure it is saved in RGB before it's uploaded?

Original source