Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] towebp filter not fool-proof against pseudo-duplicate filenames (image00001.jpeg,image00001.jpg) #2850

Open
raadegmbh opened this issue Nov 21, 2023 · 1 comment
Labels
bug Image(Helper) Issues related to the Image and ImageHelper classes

Comments

@raadegmbh
Copy link

Expected Behavior

When uploading an image and using it in a post, users expect a webp representation for the correct source image to be generated by the towebp filter, and the correct image to be therefore displayed at the end of the chain.

Actual behavior

Instead, the towebp filter overwrites competing pseudo-duplicate images:

  • image0001.jpg becomes image0001-scaled.webp
  • image0001.jpeg also becomes image0001-scaled.webp

Steps to reproduce behavior

The problem is contained in the Image/Operation/ToWebp.php file, as well as its 1.x equivalent (it seems to have been copied over from 1.x in 2.x).

A janky hotfix is to alter the filename function in line 31ff: to include the original source extension:

public function filename($src_filename, $src_extension = 'webp')
 {
     $new_name = $src_filename . $src_extension . '.webp';
     return $new_name;
 }

which immediately ameliorates the issue.

Notes

No response

What version of Timber are you using?

Timber 2.x and 1.x

What version of WordPress are you using?

Any version

What version of PHP are you using?

Any version

How did you install Timber?

Installed or updated Timber through Composer

@CedricProCab
Copy link

CedricProCab commented Nov 21, 2023

I noticed the same issue 1 hour ago with two files with the same name but with different extensions :
.i.e : velo 3.jpg and velo 3.png

The final name for the generated webp is velo-3.webp, so the second generated webp has overridden the first generated one

By doing the hotfix suggested by @raadegmbh, it will regenerate a new webp file with the original extension included, but there will be a lot of useless images in the uploads dir folders (the first generated webp without the extension included), so a clean of the uploads dir folders has to be done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Image(Helper) Issues related to the Image and ImageHelper classes
Projects
None yet
Development

No branches or pull requests

3 participants