I tried using generate_filename
yesterday but probably it was kind of late and I was trying and didnt manage to make it work, today I managed to workaround the problem without fetching the image another time like this:
$save_path = WP_CONTENT_DIR . '/tmp/' . $img_name . "-" . $nw . "x" . $nh;
$wp_img->save($save_path);
$img_name = basename($wp_img->generate_filename('suffix'));
$img_name = str_replace('-suffix', '', $img_name);
$img_url = content_url() . '/tmp/' . $img_name;
$filepath = WP_CONTENT_DIR . '/tmp/' . $img_name;
As you can see a suffix must be specified because currently the method adds a default suffix as the image size by default, and to retrieve the correct image filename + extension it must be removed afterwards.
Related Posts:
- Get Image Description
- Automatically replace original uploaded image with large image size
- How to scale up featured post thumbnail?
- Custom image size / thumbnail – Crop to aspect ratio even when source image is smaller than set dimensions
- wp_get_attachment_image_src and server path
- Change WordPress image URLs via filter
- How to resize images in wordpress without adding any compression or changing the color profile of the images, possible?
- hook into completed image upload filter
- Images uploading to wrong folder
- Why is wp_get_attachment_image not including “full” size in srcset?
- set_post_thumbnail_size not cropping featured images, but reducing proportionally
- Get img alt tag from a Image that has been uploaded through the Customizer
- Get Attachment ID from URL [duplicate]
- How to set twenty fourteen header image at 100% width?
- Can’t Display Featured Image in RSS Feed
- Filter to modify post_title after image upload?
- Automatically Add Caption in image
- Import Images from one self-hosted WordPress install to another
- How to Optimize images after uploading all images to WordPress Site?
- How to get relative URL of medium sized featured image?
- How do i reference the theme path in pages for images?
- What’s the best “insert all images” plugin?
- Using srcsets to load different images based on browser widths
- Multiple entries for one object with different cover images
- How to exclude an image size from the WordPress srcset
- WordPress Post featured image URL in the header
- Best option for photo/gallery handling?
- How do I get more image editing options in the admin?
- Plupload resize for worpdress
- File format of post image attachment
- HTTP Error when uploading files above 7mb unless using GD Image Editor
- Question about add_image_size()
- How to display a different image size for mobile
- Photography Based Design – Multiple Images Per Post
- Remove Size images without use
- Woocommerce featured image of page – not product
- How to display / include a specific jpg on a page
- Can’t seem to attach uploaded image to post and set it as thumbnail
- Grab remote images and update links in existing posts
- Store Snapshot created via wordpress to use with lightbox
- Include caption underneath post images
- Get image URL after image created from canvas and sent to WP uploads with AJAX
- How to prevent WordPress scaling large images down
- Can’t get images to align with Gutenberg editor
- Show image EXIF info
- wp_customize_image_control deprecated add_tab alternative
- How to translate get_intermediate_image_sizes?
- Modifying the HTML Output of Inserted Images
- How to check for images before echo
- Why does WordPress convert my jpg’s to png?
- How do I retrieve an image’s width and height using Advanced Custom Fields?
- wp get attachment image always gives me thumbnail
- Two “the_excerpt” questions
- How can I use wp_save_image_editor_file filter?
- Featured Image or Post Thumbnail Displaying on index.php?
- Remove “%” from strings in serialized arrays in wp_postmeta
- How to set featured image from external url programmatically
- Adding srcset to an image in ajax
- Automatically generate missing images
- Capitilize Alt/Title Tag in Image HTML, Reorder HTML Output
- How to display a sized image from Simple Fields repeatable field
- VT-resize (great alternative to timthumb) : Errors cropping (litespeed, centos 6.3)
- Allow admin roles to add images to comment replies
- Calling two images at a time? A better way?
- Random Characters in the end of every image url in post
- Image Captions Have a 10px Extra Margin, And It’s Not CSS? [duplicate]
- Image.php Problem – Post Images Not Displaying In It
- Broken thumbnails (sometimes) with TimThumb
- Is it possible to save crop to a different size of the image when in image editor?
- How do you change the fetched image of a PDF uploaded into WordPress Media Library?
- Apply manual image cropping not to thumbnail but medium_large size
- Hide or mask the url to an image
- Trying to change the URL of a product image once I upload it, but there seems to be no way to access the URL
- Trouble with Uploading and Displaying Images
- How can I insert and display copyright owner field on featured-images, pictures and galleries in articles?
- Image alt attribute
- wp_download_url() for dynamically generated image
- Non-existent child page URLs redirects to the image attachment URL instead of throwing 404
- Images not loading on wordpress.org site
- second featured post not displaying on page [closed]
- How to change img src in home-made theme, using WordPress` live customizer?
- WordPress not choosing the right image from srcset
- how to remove / hide ‘featured image’ option from side menu
- How to get attachements URL from author meta and display them?
- Images are not shown
- Replacing an Image gallery
- Missing Images in Uploads Directory (Server Only)
- Why is WordPress loading a different sized post thumbnail?
- Using the on-board image editor for featured images: edits are not being used
- change with CSS the color of an svg background image set with “background-image: url()”
- Img alt tag showing different value then entered
- Adding Multiple Images to Sidebar Through Dashboard
- Delete all thumbnails & regenerate them?
- Can I turn an image into a button?
- Why are some SVG-images not visible in my footer?
- How To Get Feature Image from Blog in Same WordPress Multisite Blog on the Parent Blog?
- WPALLIMPORT Exporting images from repeater field [closed]
- Gutenberg block HTML image rendering override
- image_get_intermediate_size always returns false
- Change of displayed images for webp versions