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

Regenerate thumbnail duplication webp file #575

Open
james58899 opened this issue Nov 7, 2022 · 13 comments
Open

Regenerate thumbnail duplication webp file #575

james58899 opened this issue Nov 7, 2022 · 13 comments
Labels
[Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) [Plugin] Performance Lab Issue relates to work in the Performance Lab Plugin only [Type] Bug An existing feature is broken

Comments

@james58899
Copy link

Bug Description

If using the Regenerate Thumbnails plugin regenerate thumbnail cause file duplication.

Steps to reproduce

  1. Enable WebP Uploads
  2. Install Regenerate Thumbnails
  3. Upload the image
  4. Click Regenerate Thumbnails in the media library
  5. Image file duplicated

Screenshots

Before regenerate:

After regenerate:

Additional Context

  • PHP Version: 8.1.12
  • Plugin Version: 1.6.0
@james58899 james58899 added the [Type] Bug An existing feature is broken label Nov 7, 2022
@felixarntz
Copy link
Member

@james58899 When you ran into this bug, did you have the checkbox to generate both WebP and JPEG (under Settings > Media) enabled or disabled?

@james58899
Copy link
Author

@james58899 When you ran into this bug, did you have the checkbox to generate both WebP and JPEG (under Settings > Media) enabled or disabled?

I didn't enable it, only generate thumbnails in webp format.

@mukeshpanchal27
Copy link
Member

@james58899 thanks for reporting the issue.

I replicate the issue when I regenerate the image using the plugin. The above PR resolves the issue with the full-size image. I find one more bug when I regenerate images multiple times.

Images after the first regeneration:
Screenshot 2022-11-28 at 3 37 37 PM

Images after the second regeneration:
Screenshot 2022-11-28 at 3 37 01 PM

@mehulkaklotar
Copy link
Member

mehulkaklotar commented Nov 29, 2022

@mukeshpanchal27 Actual issue is with replacing original image with custom mime type version here in this line: https://github.com/WordPress/performance/blob/trunk/modules/images/webp-uploads/load.php#L136

So it creates 2 issues there.

  1. Regenerating images: First regeneration has no issues because till this time, the original image is not replaced. After the first regeneration, metadata is updated. The original file is being replaced with custom mimed image. So second regeneration actually takes that replaced file instead of original uploaded file, that's why the sub sizes and full image have naming issues.
  2. Delete attachment: As per above scenario, the first regeneration replaces the original image with custom mimed image, metadata doesn't have any point of reference to the original uploaded file, so when we delete the attachment, that file remains in the file system.

@eclarke1 eclarke1 added this to Backlog in [Focus] Images via automation Mar 3, 2023
@eclarke1
Copy link

eclarke1 commented Mar 3, 2023

Adding @adamsilverstein I added this to Images and the Needs Triage label. Please advise on next steps.

@adamsilverstein
Copy link
Member

If using the Regenerate Thumbnails plugin regenerate thumbnail cause file duplication.

@james58899 - I assume you are using this plugin. With this plugin, unless you enable the "Delete thumbnail files" option, the old files are left in place when doing a regenerate command. Unless this box is checked WordPress creates new files and will generate new filenames as needed.

Closing this as "works for me" because this looks like the expected behavior to me. If I have missed something, please feel free to re-open this issue.

[Focus] Images automation moved this from Backlog to Done Mar 20, 2023
@james58899
Copy link
Author

@adamsilverstein The issue is image-jpg.webp file regenerates as image-jpg-webp.webp and the original image replace as image-jpg.webp, which doesn't look like the expected behavior.

Regenerating the thumbnail should not change the information of the original image, nor should it infinitely generate new webp files.

@adamsilverstein
Copy link
Member

Regenerating the thumbnail should not change the information of the original image, nor should it infinitely generate new webp files.

I will give this a test. The file naming probably isn't a concern as long as the file meta is right.

  • Can you confirm if you have the "Delete thumbnails option" checked?
  • Can you test without the plugin active to see what files are generated/is the behavior different?

@adamsilverstein
Copy link
Member

@james58899 I am still unable to reproduce the issue, have you tested with the latest version of the plugin? is your original upload a jpeg? do you have a.custom filter applied to generate both jpeg and webp?

@james58899
Copy link
Author

james58899 commented Apr 4, 2023

@adamsilverstein Yes, the issue still exists, please reopen the issue.
According to the above comment, this issue is obviously reproducible, and there is a PR related to this issue, how did you try to reproduce this issue?

Enable Performance Lab

Settings


The picture was just uploaded

Everything works fine when the image is just uploaded.


First time regenerate thumbnail

After the thumbnail is regenerated for the first time, the original image is replaced with webp, and a new webp file is generated.



Second time regenerate thumbnail

After the thumbnails are regenerated a second time, the original images are replaced again, and a bunch of new webp thumbnails are generated.



Click Delete permanently

A lot of files are left in the folder without being deleted.

Disable Performance Lab

The picture was just uploaded


First time regenerate thumbnail



Second time regenerate thumbnail

Same as first time.

Click Delete permanently

All files have been deleted.

@ddur
Copy link

ddur commented May 21, 2023

@james58899

I can confirm your findings.

Initially, I couldn't reproduce issue, until I disabled [_] Generate JPEG files in addition to WebP, like you did here.

@adamsilverstein

@mukeshpanchal27
Copy link
Member

@adamsilverstein I'm going to reopen the issue as i still replicate the issue.

Steps to reproduce

  1. Install and activate the Performance Lab plugin with default settings (Enable WebP Uploads)
  2. Install Regenerate Thumbnails plugin
  3. Upload the image. ex. car.jpeg.
Screenshot 2023-05-29 at 4 36 03 PM
  1. Go to Media > Edit image then click on Regenerate Thumbnails button.
Screenshot 2023-05-29 at 4 36 51 PM
  1. Again click on Regenerate Thumbnails button.
Screenshot 2023-05-29 at 4 37 40 PM

[Focus] Images automation moved this from Done to Backlog May 29, 2023
@adamsilverstein
Copy link
Member

Excellent, thank you @mukeshpanchal27 and @james58899 for the detailed steps to reproduce. I will retest and see what the best solution is. It looks like in an attempt to avoid name collisions we are inadvertently creating extra names.

I'm curious (and will test) - if you delete the original image, are you left with stray images that aren't deletes?

@mukeshpanchal27 mukeshpanchal27 added the [Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) label May 31, 2023
@felixarntz felixarntz added the [Plugin] Performance Lab Issue relates to work in the Performance Lab Plugin only label Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) [Plugin] Performance Lab Issue relates to work in the Performance Lab Plugin only [Type] Bug An existing feature is broken
Projects
Status: Not Started/Backlog 📆
Development

Successfully merging a pull request may close this issue.

8 participants