0

Since WP 3.0 does not support hard crop anymore (the only way to crop is in media manager), how am I suppose to dynamically crop my thumbnails? I don't want to crop them manually one by one...

2

http://codex.wordpress.org/Class_Reference/WP_Image_Editor

http://codex.wordpress.org/Function_Reference/wp_get_image_editor

$image = wp_get_image_editor( 'cool_image.jpg' );
if ( ! is_wp_error( $image ) ) {
    $image->rotate( 90 );
    $image->resize( 300, 300, true );
    $image->save( 'cool_image.jpg' );
}

Repalce cool_image.jpg with a variable holding the path to the image you want to edit. Not a copy and paste solution but should put u on the right track. There is a crop function.

crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ); 
//Crops Image. 
  • Really nice! So this is the class that is used by the image editor in the admin panel? – user25893 Jul 9 '13 at 14:58
  • 1
    I am not cerain but I have made that assumption. WP_Image_Editor class was added in 3.5.2 I believe. Its good to read those release notes when you update wordpress to see what new bells and whistles they added :). – Vigs Jul 9 '13 at 15:00

Your Answer

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