Check for CMYK images during uploader (4 posts)

  1. Achim Meurer
    Posted 3 years ago #

    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?


  2. Achim Meurer
    Posted 3 years ago #

    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?

  3. praeix
    Posted 3 years ago #

    @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.

  4. Achim Meurer
    Posted 3 years ago #

    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...


Topic Closed

This topic has been closed to new replies.

About this Topic