Jump to content

webP variants are not automatically deleted


howdytom
 Share

Recommended Posts

Hi there,

When I delete all image variants, ProcessWire does not remove previously generated webP files from the assets/files folder. The variants list is empty. PNG and jpeg images are removed just fine, but webP files are left on the server. This will increase dramatically disk space on bigger projects. How can I automatically clean up webP leftovers on deletion?

Steps to reproduce:

I am using a ProFields:repeater Matrix with a FieldtypeImage. webP variations are created with $img_1920->webp->url,  $img_1600->webp->url ... in a <picture> element.

1_PW-variations-list.thumb.png.2417e2edd76c4067063ec8cf9a1e78a2.png

1. Within the repeater image field, → Variations → Delete checked → close the modal → Save
2. When I go to assets/files/1134/ all png variations are deleted. webP variations are still kept e.g. testgrafik-logodesign.1600x0se.webp, testgrafik-logodesign.1920x1080se.webp

2_PW-asset-folder.png.9163c9a81735349e34fc158a1a0222df.png

3. When I open again the variations modal → the variation list is still empty, except the original file.

3_PW-variations-list.png.72dd81dd0bb1f60f28d263b565f65154.png
4. However deleting the repeater Item, will also remove all files from assets/files directory.

ProcessWire 3.0.165

Link to comment
Share on other sites

Normally they get removed together with the other variants, so there must be some sort of anomaly or quirks in your site happened. But without any informations where and how you create(d) the webp variations and where and how you remove(d) the variations, any help seems impossible.

Link to comment
Share on other sites

1) Are you able to test the site (or a copy of it) with the current dev version 3.0.183/4 (what seems to become the next stable version next week) and check if the latest RepeaterMatrix version is on start too?

2) Also I want to see the exact code how you create the (primary png/jpeg) variations and where the webp() call is executed. Means the whole code for a picture / srcset elements markup please. 

No 1) would be just to be save that there are not already fixes in with the later version(s), and no 2) seems to be the only (for me known) point where the quirks may come from. 

Link to comment
Share on other sites

@horst, thanks. 

I gave dev version 3.0.183 and RepeaterMatrix v5 a try. 

  Deleting the JPG/PNG variations will delete all files within /assets/files/1134/.
  Deleting the webP variations will remove them from the variants list, however all files still remain in the /assets/files/1134/ directory.

Maybe I am missed something in my RepeaterMatrix code. My markup code:

<?php if(count($page->img_test)) {
foreach($page->img_test as $image){
  $imgsettings = array(
    'quality' => 80,
    'cropping' => 'southeast'
  );
    $img_1920 = $image->size(1920, 1080, $imgsettings);
    $img_1600 = $image->size(1600, 0, $imgsettings);
    $img_500 = $image->size(500, 0, $imgsettings);
    echo "
    <picture>
      <source srcset='{$img_1920->webp->url}' loading='lazy' type='image/webp' alt='{$img_1920->description}' sizes='100vw' srcset='{$img_500->webp->url} 500w, {$img_1600->webp->url} 1600w, {$img_1920->webp->url} 1920w' class='canvas__fullsize-img'>
      <source srcset='{$img_1920->url}' loading='lazy' type='image/{$image->ext}' alt='{$img_1920->description}' sizes='100vw' srcset='{$img_500->url} 500w, {$img_1600->url} 1600w, {$img_1920->url} 1920w' class='canvas__fullsize-img'>
      <img src='{$img_1920->url}' loading='lazy' alt='{$img_1920->description}' sizes='100vw' srcset='{$img_500->url} 500w, {$img_1600->url} 1600w, {$img_1920->url} 1920w'>
    </picture>";
  }
}

 

Link to comment
Share on other sites

  • 7 months later...

@horst @howdytom

Hi, same here. I empty the variants list. Original formats gets deleted, webp files remains in the asset folder. In my case, wether the image field is placed in a RepeaterMatrix (v5, latest) or is a single PW Field. It makes no difference.

This is a big drawback. In my current project there were a buch of files corrupted on creation (webp). Which causes strange behaviour in google chrome. Inspected this a couple of hours,- until i found out the webp files won't get deleted physically form the asset folder. And so never being recreated. Deleting them manually solves the problem. But iterating through all assets folders by hand i cannot afford. Get rid off them with a script seems the way to go...

While debugging i tried out all possible execution markup and calls as i assumed somethings wrong with my integration/code. But this was not the case. All scenarios (s. below) works fine since it turned out the only problem were the remaining webp files.

PW 3.0.192 dev, GD lib image sizer Engine.

@horst If there is anything i can do to help further exploring the behaviour, please let me know.

Excerpt: With $config->useWebP = true; , lazysizes

<?php
  $options = array(
  'upscale' => false,
  'cropping' => 'center'
  );

  $page_image_palm = $page->image_head->size(480, 640, $options);
?>

<picture>
  <source class="" media="(max-width: 480px)" data-srcset="<?= $page_image_palm->url; ?>" alt="">
  //...
  <img class=" lazyload" data-srcset="<?= $page_image_palm->url; ?>" alt="">
</picture>

Excerpt: With $config->useWebP = false; / Markup with default API call like in https://processwire.com/blog/posts/webp-images-on-an-existing-site/

<picture>
  <source class="" srcset="<?= $page_image_palm->webp->url; ?>" type="image/webp">
  <img class="" src="<?= $page_image_palm->url; ?>" alt="">
</picture>

And some other calls in between...

Link to comment
Share on other sites

Thanks for getting back to this issue. So far I did not find a solution. When I select and delete all or single variations, WebP files remain in the asset directory. This issue occurs with RepeaterMatrix and also in single PW image field.

I think it is a ProccessWire bug? ?‍♂️

Link to comment
Share on other sites

Hi guys! ( @howdytom @olafgleba )

Please are you able to post your setups / configs to this github-issue?

I think this would be of great help for Ryan.

  • Please put in your image sizer config settings, 
  • the lines of code how you use
  • and where you use it. (template-file, repeater, etc)

Also please only issues with the core image field.

I had posted example code there, to help reproduce the issue in an automated way, but I think that Ryan now think that the issue only is with my special code. !!

Many thanks!

  • Like 3
Link to comment
Share on other sites

  • 4 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...