WP Smush API integration with image resize script

Hi,

In addition to WP Smush Pro's default functionality my team uses a custom resize function which gives us extra control over how images are cropped. In concept, this plugin works similar to timthumb, our resized images go into uploads/resized/imagename.jpg

My question is can the WP Smush Pro API be used within custom scripts, where we can pass our cropped images to WP Smush so the output file get the same compression like files in the media library?

Any info would be appriciated
Thanks

  • Nithin

    Hi Adam,

    Hope you are doing good today. :slight_smile:

    WP Smush Pro is more of a SAAS plugin, as it makes use of our servers when it comes to optimizing images, this has a lot to do with decreasing the timeout, and smushing out images with ease. I have already passed your query for the developers consideration, but at this moment, I'm afraid there isn't any integration available to make use of your script.

    We're always grateful for your feedback. Please let us know if you need any further assistance. Have a nice day. :slight_smile:

    Best Regards,
    Nithin

  • Shashi

    i have a similar situation most of the large site will use some kind of image resize function cause if you have over 40k posts adding an image size for each image size will make the site very large in my case i have a custom function im calling wp_get_image_editor to resize is there any kind of function or hook i can call to get the result of the wp_get_image_editor passed to smush pro

    to be more clear im using something like
    $editor = wp_get_image_editor( $file_path );
    ... some calculation code then i pass my desired width and height
    $editor->crop( $src_x, $src_y, $src_w, $src_h, $dest_width, $dest_height );
    $saved = $editor->save( $dest_file_name );
    // here i can call smush pro
    ..... meta data code
    wp_update_attachment_metadata( $get_attachment[0]->ID, $metadata );

  • Umesh Kumar

    Hi Shashi,

    Is it not possible for you to use the WP Smush resize functionality? you can even hook into

    apply_filters( 'wp_smush_resize_sizes', array(
    				'width'  => $this->max_w,
    				'height' => $this->max_h
    			), $file_path, $id );
    , if you want to provide the custom dimensions for a specific image.

    One limitation is it will store the image in designated folder only, no option to save it in a custom folder. But you can backup original image using the filter wp_smush_resize_create_backup, return true to enable the backup.

    In case you still want to use custom plugin for resizing, you must be updating the image dimension in image metadata, which requires you to run the function wp_update_attachment_metadata(). So after resizing if you're running that function and auto smush is on, the images will be optimised by default.

    Hope that helps.

    Cheers

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.