I've been trying to resize an image client-side before uploading (see this question). I'm now trying to resize server-side before uploading.

I think wp_handle_upload_prefilter is the filter I should be using for this. Here's my attempt so far which isn't working:

function my_resize_before_upload( $file ) {
    $upload = wp_upload_bits( $file['name'], null, file_get_contents( $file['tmp_name'] ) );
    $image = wp_get_image_editor( $upload['file'] );
    if ( ! is_wp_error( $image ) ) {
        $image->resize( 80, 80 );
        $image->save( $upload['file'] );
    return $file;
add_filter( 'wp_handle_upload_prefilter', 'my_resize_before_upload' );

How can I resize an image server-side before uploading?


  • The server has no access to the file before it has been uploaded. This is impossible. – fuxia Nov 7 '14 at 0:30
  • Thanks for the info. Not what I wanted to hear but now I know I can move on to explore alternatives. Thanks again – henrywright Nov 7 '14 at 0:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.