Wp get image editor do not save image

wp_get_image_editor () resizes and saves images on the local host (mamp), but it just doesn’t work on the server (saved) there is no error, here is my code

function image_crop($url, $name){ $image = wp_get_image_editor( $url ); if ( ! is_wp_error( $image ) ) { $image->resize( 100, 140, true ); $data = $image->save( $name.'_'.$id.'.png' ); } if( ! is_wp_error( $data ) ) { return "ok"; }else{ return "Error"; } } 

this function returns "ok", but the destination directory is empty, with no images.

+6
source share
1 answer

If you want to save the image using the wp_get_image tool editor, you must do the following:

 // load image object // the best way to use picture path instead of url, as in the example below $image = wp_get_image_editor( $_SERVER['DOCUMENT_ROOT'].'/wp-content/uploads/2015/10/image.png' ); // process image if ( ! is_wp_error( $image ) ) { $image->resize( 100, 140, true ); // save the root site irectory called new_image.png // use path to the folder where you want to save a picture $image->save( $_SERVER['DOCUMENT_ROOT'].'/new_image.png' ); } 

The folder in which you are holding the image should be allowed to write, for example 755 or 777.

0
source

All Articles