I need to resize a few existing images in my upload directory so doing some tests with wp_get_image_editor. Please check the example code below.
$img = wp_get_image_editor( ABSPATH.'test/flower.jpg' );
if ( ! is_wp_error( $img )) {
$img->resize( 800, NULL, false ); //resize to max-width of 800px.
$filename = $img->generate_filename( 'custom-suffix-string', NULL, 'jpg');
$saved = $img->save($filename);
//information returned by $saved
echo "Filename: ".$saved['file']."<br>";
}
As you can see I can add a custom suffix with line-4 of the code. So the name of my resized file will be flower-custom-suffix-string.jpg
. The problem is I need it to return as NULL.
If I use generate_filename( NULL, NULL, 'jpg');
the echoed result is Filename: flower-800x667.jpg
. So basically I am trying to get the name of the RESIZED image as flower.jpg
same as original and get rid of -800x667
from the name. If the process overwrites/deletes the original file, that would not be a problem. Any suggestions or any other way to achieve this ? TIA.
UPDATE : I ended up using the code below. Thanks for the tip @Zakir
$filename = $img->generate_filename( 'temp', NULL, NULL);
$new_name = str_replace('-temp', '', $filename);
$resized_img = $img->save($new_name);