Title: File naming bug when using output mapping
Last modified: October 4, 2026

---

# File naming bug when using output mapping

 *  [oobi75](https://wordpress.org/support/users/oobi75/)
 * (@oobi75)
 * [2 days, 19 hours ago](https://wordpress.org/support/topic/file-naming-bug-when-using-output-mapping/)
 * Context: we’re using a filter to set the image editor output format to webp. 
   Originals are uploaded as jpeg or png and resized versions are all generated 
   as webp.
 * add_filter(‘image_editor_output_format’, function (array $formats): array {
    
   $formats[‘image/jpeg’] = ‘image/webp’; $formats[‘image/png’] = ‘image/webp’; 
   return $formats;});
 * **Two bugs when an `image_editor_output_format` mapping is active (e.g. JPEG 
   → WebP). Crop Thumbnails 1.9.7, WordPress 7.1.2**
 * **1. Crop filenames keep the source extension**
 * With JPEG → WebP mapped, cropping `photo.jpg` creates `photo.jpg-150x150.webp`.
   WordPress’s own sub-size would be `photo-150x150.webp`.
 * Cause: in `CptSaveThumbnail::generateFilename()`, `$ext` is switched to the output
   extension (`webp`) before the base name is taken. `wp_basename($file, '.webp')`
   doesn’t match `photo.jpg`, so `.jpg` stays in the name. Taking the base name 
   with the original extension before swapping `$ext` fixes it.
 * **2. Re-cropping a size can delete a file another size still uses**
 * WordPress gives sizes with identical dimensions one shared file. For example,`
   square` (1024×1024 crop) and `large_square` (1024×1024 crop) both point to `photo-
   1024x1024.jpg`.
 * Steps:
    1. Crop `square` only.
    2. The crop gets a new name, `photo.jpg-1024x1024.webp`, so `filter_shouldDeleteOldFile()`
       returns true and `photo-1024x1024.jpg` is deleted.
    3. `large_square` still points at `photo-1024x1024.jpg`, which no longer exists,
       so it renders as a broken image.
 * This happens whenever the crop’s filename differs from the old one, which is 
   every crop on a site using an output-format mapping. Suggested fix: before deleting,
   check that no other size in the attachment metadata references the same file.
 * Workarounds we’re using in the meantime: a `crop_thumbnails_filename` filter 
   that strips the stray extension, and a `crop_thumbnails_should_delete_old_file`
   filter at priority 20 that keeps files still referenced by another size.

You must be [logged in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Ffile-naming-bug-when-using-output-mapping%2F%3Foutput_format%3Dmd&locale=en_US)
to reply to this topic.

 * ![](https://ps.w.org/crop-thumbnails/assets/icon.svg?rev=1228698)
 * [Crop-Thumbnails](https://wordpress.org/plugins/crop-thumbnails/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/crop-thumbnails/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/crop-thumbnails/)
 * [Active Topics](https://wordpress.org/support/plugin/crop-thumbnails/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/crop-thumbnails/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/crop-thumbnails/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [oobi75](https://wordpress.org/support/users/oobi75/)
 * Last activity: [2 days, 19 hours ago](https://wordpress.org/support/topic/file-naming-bug-when-using-output-mapping/)
 * Status: not resolved