Since in wordpress, the files/images uploaded are stored in 3 different sizes thus taking up the memory. I have a code that re sizes the image given the URL of that image. The code to resize is:
$img = wp_get_image_editor( $image_url );
if ( ! is_wp_error( $img ) ) {
$img->resize( 200, 200, false );
$filename = $img->generate_filename(
'final',
ABSPATH.'wp-content/uploads',
NULL
);
$img->save($filename);
}
So I want to use this code to resize the image from the local path of the user so that I don't use up too much of my memory. Can anyone tell me how to get the local path and url of the file uploaded by url?
How about this for getting the local path of an image from its URL? :
function ContentUrlToLocalPath($url){
preg_match('/.*(\/wp\-content\/uploads\/\d+\/\d+\/.*)/', $url, $mat);
if(count($mat) > 0) return ABSPATH . $mat[1];
return '';
}
It assumes the file is located in the uploads folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With