简体   繁体   中英

How to crop image from center using wp_image_editor

I am working on WordPress plugin. In plugin the user upload images from meta field and in back end i use wp_image_editor for cropping and re sizing the images. The images re sized very well but on cropping the images not cropped very well. I give x-dimension 100 and y-dimension 0.

$resize_img = wp_get_image_editor( $wpc_prod_img['wpc_resize_img'] );
if ( ! is_wp_error( $resize_img ) ) {
   $resize_img->crop( 100, 0, $wpc_image_width, $wpc_image_height, NULL, NULL, false );
}

I want to cropped image from center of x-dimension and center of y-dimension. I tried this but its not work

$resize_img->crop( 'center', 'center', $wpc_image_width, $wpc_image_height, NULL, NULL, false );

How can i do this. Is there any solution

Try this code:

$crop = array( 'center', 'center' );
resize( $max_w, $max_h, $crop);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM