performance icon indicating copy to clipboard operation
performance copied to clipboard

Regenerate thumbnail duplication webp file

Open james58899 opened this issue 3 years ago • 14 comments

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 avatar Nov 07 '22 07:11 james58899

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

felixarntz avatar Nov 08 '22 23:11 felixarntz

@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.

james58899 avatar Nov 09 '22 00:11 james58899

@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

mukeshpanchal27 avatar Nov 28 '22 10:11 mukeshpanchal27

@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.

mehulkaklotar avatar Nov 29 '22 10:11 mehulkaklotar

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

eclarke1 avatar Mar 03 '23 11:03 eclarke1

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.

adamsilverstein avatar Mar 20 '23 14:03 adamsilverstein

@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.

james58899 avatar Mar 20 '23 15:03 james58899

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 avatar Mar 20 '23 16:03 adamsilverstein

@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?

adamsilverstein avatar Apr 03 '23 22:04 adamsilverstein

@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.

james58899 avatar Apr 04 '23 05:04 james58899

@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

ddur avatar May 21 '23 19:05 ddur

@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

  4. Go to Media > Edit image then click on Regenerate Thumbnails button. Screenshot 2023-05-29 at 4 36 51 PM

  5. Again click on Regenerate Thumbnails button. Screenshot 2023-05-29 at 4 37 40 PM

mukeshpanchal27 avatar May 29 '23 11:05 mukeshpanchal27

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?

adamsilverstein avatar May 30 '23 18:05 adamsilverstein

I can confirm the same behaviour when using .avif format.

kleenebrooker avatar Oct 24 '24 08:10 kleenebrooker