- Issue created by @Chris Burge
- ๐ช๐ธSpain candelas
Good to learn about this bug. I was going to convert all images to webp.
I hope you to have time to make a patch.
Thanks - ๐ง๐ชBelgium bramvandenbulcke
I have been using the conversion to webp functionality since launch (in core). I have seen this behaviour from the beginning. But I thought this was intentional. Apparently not!
- ๐ฎ๐ณIndia pradhumanjainOSL
pradhumanjain2311 โ made their first commit to this issueโs fork.
- Merge request !7776Issue #3413632: When Converting an Image's Format with Image Styles, Replace... โ (Open) created by Unnamed author
- ๐บ๐ธUnited States w01f
ChatGPT suggests that handling conversions by replacing, rather than appending, the new extension may be better for SEO and caching. It suggests 2 methods:
1. Adjust Your Conversion Process
If youโre using a tool (like ImageMagick, GD, or a dedicated Drupal module) to convert images to WebP, check its configuration. Some tools allow you to specify a naming pattern so that the original extension is replaced rather than appended. For example, instead of appending .webp to DSC_3347.jpeg, youโd configure it to replace .jpeg with .webp.2. Use a Drupal Hook to Alter the Output URL
In Drupal, you can implement a hook (such as hook_image_style_url_alter()) to modify the generated image URL. For example:php Copy /** * Implements hook_image_style_url_alter(). */ function mymodule_image_style_url_alter(&$url, $style_name, $uri) { // Adjust only for styles that convert to WebP. if ($style_name == 'your_webp_style') { // Replace a filename ending in .anything.webp with just .webp. $url = preg_replace('/\.[^.]+\.webp$/', '.webp', $url); } }
Replace 'your_webp_style' with the actual machine name of your image style.
After implementing this hook, clear your caches so the changes take effect.