Option to save img_url formatted images in the same folder

For the {{img_url}} helper, would it be possible to have an option/configuration to save the formatted images in the same folder instead of the /format/ folder?

It would allow us to conditionally serve WebP and AVIF images easily with NGINX and would replace the need to have multiple s in our HTML code.

References:

Currently, I’ve been able to modify the core/frontend/utils /images.js file with the following changes, but this requires having an external cron/script to transform the images into new modern format images… :confused:

Current

  const sizeDirectoryName = prefixIfPresent('w', width) + prefixIfPresent('h', height);
  const formatPrefix = requestedFormat && imageTransform.canTransformToFormat(requestedFormat) ? `/format/${requestedFormat}` : '';

  return [imgBlogUrl, urlUtils.STATIC_IMAGE_URL_PREFIX, `/size/${sizeDirectoryName}`, formatPrefix, imageName].join('');

Modified

  const sizeDirectoryName = prefixIfPresent('w', width) + prefixIfPresent('h', height);
  const extension = imageName.split('.').pop()
  const imageWithNewExtension = requestedFormat && imageTransform.canTransformToFormat(requestedFormat) ? imageName.substring(0, imageName.lastIndexOf(extension)) + requestedFormat : imageName;

  return [imgBlogUrl, urlUtils.STATIC_IMAGE_URL_PREFIX, `/size/${sizeDirectoryName}`, imageWithNewExtension].join('');