Thumbs unnecessarily regenerated

Hi,

I’m having a strange issue with using the thumb() function on my live server (with localhost everything is fine). I think this is somewhat similar to this issue, but as this did not seemed to be resolved, and I am using Kirby 3, it made sense to create a new thread.

Basically I am using a content representation as a JSON endpoint which I request in the browswer using Vue.

I create thumbs on the server side, and as I said request them with an ajax call in the browser, so to handle images my representation looks like this:

function returnImages($page, $img) {
  $imgObj = new stdClass();
  $image = $page->image($img);
  $imgObj->url = $image->url();
  $imgObj->ratio = $image->ratio();
  $imgObj->orientation = $image->orientation();
  $imgObj->caption = $image->caption()->value();
  $imgObj->thumbs['xs'] = $image->thumb(['width' => 600, 'quality' => 80])->url(); 
  $imgObj->thumbs['sm'] = $image->thumb(['width' => 900, 'quality' => 80])->url(); 
  $imgObj->thumbs['md'] = $image->thumb(['width' => 1024, 'quality' => 80])->url(); 
  $imgObj->thumbs['lg'] = $image->thumb(['width' => 1200, 'quality' => 80])->url(); 
  $imgObj->thumbs['xl'] = $image->thumb(['width' => 1600, 'quality' => 80])->url(); 
  return $imgObj;
}

So this function takes a file and I get back something like this:

{
"url": "http://127.0.0.1:9000/media/pages/home/detox-faces/657099124-1577913447/boiling_crab.jpg",
"ratio": 1.0079744816586922,
"orientation": "landscape",
"caption": "Untitled, 200 x 400, oil on canvas, 2019",
"filename": "boiling_crab.jpg",
"thumbs": {
  "xs": "http://127.0.0.1:9000/media/pages/home/detox-faces/657099124-1577913447/boiling-crab-600x-q80.jpg",
  "sm": "http://127.0.0.1:9000/media/pages/home/detox-faces/657099124-1577913447/boiling-crab-900x-q80.jpg",
  "md": "http://127.0.0.1:9000/media/pages/home/detox-faces/657099124-1577913447/boiling-crab-1024x-q80.jpg",
  "lg": "http://127.0.0.1:9000/media/pages/home/detox-faces/657099124-1577913447/boiling-crab-1200x-q80.jpg",
  "xl": "http://127.0.0.1:9000/media/pages/home/detox-faces/657099124-1577913447/boiling-crab-1600x-q80.jpg"
  }
}

Which is all fine. My problem is that it seems that now and again when I make this request (not every single time, maybe once in ten), a new set of thumbs are created, which, rather than simply serving up an existing file.

Surely this is not normal behaviour? Is there a better way to create these thumbs?

For some context I am using the GD library, running php 7.2 on apache on Ubuntu 16.04.6. I am getting nothing significant in my error log.

Thanks.

What makes you think that new thumbs are generated? Do they get new timestamps?

Yes - I could tell as the response time was very slow in the browser (as the thumbs were being created), then I looked and saw new folders in the /media folder were being generated (with new timestamps).

I remember a similar issue and it was related to the server time. Sadly, I don’t remember the exact solution but Kirby thought the source files were newer than the existing thumbs and thus created new ones. Maybe that gives you an direction how to solve this.