performance icon indicating copy to clipboard operation
performance copied to clipboard

Allow for modification or removal of the -jpg suffix added to webp images, generated from jpg files

Open jamesozzie opened this issue 3 years ago • 12 comments

Feature Description

As per a user request in the forums allow for modification or removal of the naming structure of webp images that are generated from jpg files. At present when webp files are created from uploaded jpg they include a -jpg suffix.

Example: If I upload myimage.jpg the respective webp version will be titled myimage-jpg.webp

  • Support topic
  • This is the first such report in the WordPress support forums

Update: The below support topics also reference issues or queries regarding the file names that were added:

  • https://wordpress.org/support/topic/modified-file-names/
  • https://wordpress.org/support/topic/images-rename/

jamesozzie avatar Sep 23 '22 15:09 jamesozzie

I second that, a filter for the suffix would be great! i used a plugin that created myimage.jpg -> myimage.jpg.webp and i'm serving those images via url rewrite. So to be able to keep serving my existing images and create new ones with the performance lab plugin it would be handy to be able to to change the suffix of the generated files!

Thx paul

PaulSchiretz avatar Sep 27 '22 01:09 PaulSchiretz

Thanks, Paul, for the comment.

Some background for the image extension. Plugin added the original image's extension to the WebP file name for its uniqueness in #444, for two or more images share the same file name but different mime types.

If you are aware of the rise of the same file name with different mime types issue, the filter is a good option for removing file name extensions.

Filter that adds an extension to the image name. The default value for this filter is true, so it doesn't affect the current behavior of the plugin.

/**
 * Filters whether image extensions are allowed for image names.
 *
 * By default the performance lab plugin will use the image extension for uniqueness 
 * purposes for the additional mime type image name.
 *
 * @since n.e.x.t
 *
 * @param bool $allowed_image_extension Add the image extension to the file name. Default true.
 */
$allowed_image_extension = apply_filters( 'webp_uploads_image_name_with_extention', true );

@felixarntz and @adamsilverstein, I would be interested to hear your thoughts on this?

Please review and suggest wording if I missed anything.

mukeshpanchal27 avatar Sep 27 '22 05:09 mukeshpanchal27

I'm open to the idea of introducing some developer control here, however we may want something broader to control naming overall.

We may want to hold and revisit this once we consider adjusting the approach in the plugin to match where we wound up in core.

adamsilverstein avatar Sep 29 '22 16:09 adamsilverstein

How about selections between: filename.jpg to filename.jpg.webp or filename.webp I need option: filename.jpg.webp.

kenny-nt avatar Oct 19 '22 15:10 kenny-nt

@PaulSchiretz

I second that, a filter for the suffix would be great! i used a plugin that created myimage.jpg -> myimage.jpg.webp and i'm serving those images via url rewrite. So to be able to keep serving my existing images and create new ones with the performance lab plugin it would be handy to be able to to change the suffix of the generated files!

Thx paul

@kenny-nt

How about selections between: filename.jpg to filename.jpg.webp or filename.webp I need option: filename.jpg.webp.

That would be compatible with redirection convention used on most hosting providers, even WordOps is using it by default.

Current renaming convention is pure nonsense. I guess, someone was mislead or inspired with -cropped and -rotated suffix, but that was appropriate because it is for completely different purpose.

Anyways, I wonder what else could be purpose of WebP upload module keeping jpeg thumbnails than enabling redirection for WebP enabled/disabled browsers? Same convention should be implemented for original.jpg

ddur avatar Jun 01 '23 08:06 ddur

@adamsilverstein

I'm open to the idea of introducing some developer control here, however we may want something broader to control naming overall.

We may want to hold and revisit this once we consider adjusting the approach in the plugin to match where we wound up in core.

Upload name is always checked for duplicate names and renamed. Thumbnails names just follow original / renamed file. That works without problems for decades. Same will work for .jpeg.webp because it will never be duplicate of original-name.jpeg. Even when .jpeg thumbnails are not generated (skipped).

ddur avatar Jun 01 '23 09:06 ddur

@adamsilverstein

We may want to hold and revisit this once we consider adjusting the approach in the plugin to match where we wound up in core.

This "thing" should never "wound up in core". Image Editor Class is already capable of generating both media/types (when library supports), and is already capable to regenerate images. Which is not the case with WebP - upload module that does it's "thing" only on upload. All you have to do is to handle name and use _save method twice. That would enable generating and regenerating older images for JPEG and PNG formats.

ddur avatar Jun 01 '23 12:06 ddur

Which is not the case with WebP - upload module that does it's "thing" only on upload.

@ddur are you sure about that? WebPs should be generated when regenerating images as well as at upload.

adamsilverstein avatar Apr 26 '24 22:04 adamsilverstein

This issue just came up in another support topic: https://wordpress.org/support/topic/images-rename/

westonruter avatar Aug 12 '24 20:08 westonruter

I second that, a filter for the suffix would be great! i used a plugin that created myimage.jpg -> myimage.jpg.webp and i'm serving those images via url rewrite. So to be able to keep serving my existing images and create new ones with the performance lab plugin it would be handy to be able to to change the suffix of the generated files!

Thx paul

Hello Paul, I too used Performance Lab to convert images to AVIF and had the same problem with files renamed with the suffix (tilde)jpg(tilde)avif. In the meantime they find a solution I as a temporary solution used the plugin ‘Media File Renamer’ to remove this suffix from all files in bulk. The plugin works very well. https://wordpress.org/plugins/media-file-renamer

reteinformatica avatar Aug 26 '24 15:08 reteinformatica

I think it would be good to bring this up in this discussion. If I regenerate existing files more than once, the extension keeps building up...

When I regenerate thumbnails using that plugin, it creates a new file. I am creating webp files, and it works pretty great, but every time I do that to update existing files, it adds to the end of the filename: “-oldext.webp”, but it does it even to previously generated webp files. If you run it once, it changes filename.jpg to filename-jpg.webp. If you run it a second time, it creates a new file instead of replacing the existing, and changes the name to filename-jpg-webp.webp. A third time gets you filename-jpg-webp-webp.webp.

jupitercow avatar Oct 02 '24 14:10 jupitercow