• Resolved honoluluman

    (@honoluluman)


    Hello, i have the bellow code with the use of wp_handle_upload_prefilter that i can check on upload the size of an image. Could i some how create a custom task with this?
    Could you help me with the implementation?

    add_filter('wp_handle_upload_prefilter','validate_image_size');
    function validate_image_size( $file ) {
        $image = getimagesize($file['tmp_name']);
        $minimum = array(
            'width' => '400',
            'height' => '400'
        );
        $maximum = array(
            'width' => '2000',
            'height' => '2000'
        );
        $image_width = $image[0];
        $image_height = $image[1];
    
        $too_small = "Image dimensions are too small. Minimum size is {$minimum['width']} by {$minimum['height']} pixels. Uploaded image is $image_width by $image_height pixels.";
        $too_large = "Image dimensions are too large. Maximum size is {$maximum['width']} by {$maximum['height']} pixels. Uploaded image is $image_width by $image_height pixels.";
    
        if ( $image_width < $minimum['width'] || $image_height < $minimum['height'] ) {
            // add in the field 'error' of the $file array the message 
            $file['error'] = $too_small; 
            return $file;
        }
        elseif ( $image_width > $maximum['width'] || $image_height > $maximum['height'] ) {
            //add in the field 'error' of the $file array the message
            $file['error'] = $too_large; 
            return $file;
        }
        else
            return $file;
    }

    Thank you very much for your time.

Viewing 1 replies (of 1 total)
  • Plugin Author Steve Burge

    (@stevejburge)

    Hi @honoluluman. Thanks for using PublishPress Checklists.

    Our plugin could definitely be a good basis for a feature like this, but our support doesn’t extend to custom code.

Viewing 1 replies (of 1 total)
  • The topic ‘Create Limit image resolution on upload custom task’ is closed to new replies.