Support » Plugins » Hacks » Check for CMYK images during uploader

  • Hi folks,

    is there a way to check the image for cmyk mode during the file upload?

    eG: upload a cmyk image and after upload the error message will appear with a hint to convert the image to RGB before uploading..

    Anyone an idea?


Viewing 3 replies - 1 through 3 (of 3 total)
  • I’ve found this code:

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

    How can I hook this to the uploader? Or other ideas?

    @almstudio – Are you using the built-in WordPress uploader and are you using the Settings API to store this information or a different method?

    I recommend using the Settings API as it does a lot of stuff for you. (Just Google “wordpress settings api handle file upload” and you should find a bunch in there). However for specifics, whatever ID you give the field that the image is being uploaded from will be used in the $_FILES superglobal to find it.

    Like this:

    if ( $_FILES['id_of_image'] ) and then you could do your checking of the channels from there.

    thanx for the answer. And yes, I’m using the built-in uploader. I will google for the settings API, never heard of that or used that before 😉

    I’ll have a try…


Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Check for CMYK images during uploader’ is closed to new replies.