Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#241 Today 19:45:20

etc
Developer
Registered: 2010-11-11
Posts: 5,633
Website GitHub

Re: Automatic thumbnails for Textpattern

Bloke wrote #341836:

EDIT: is that to do with the location of the redirect in the serveRenderedImage() method? Was it better in serveFile()? I dunno.

There should be no difference, serveFile() just set some headers. What if you try TEXTPATTERN_THUMB_TTL = 0?

Offline

#242 Today 20:04:48

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,263
Website GitHub

Re: Automatic thumbnails for Textpattern

etc wrote #341837:

What if you try TEXTPATTERN_THUMB_TTL = 0?

With a 308, no difference. In fact, first time I tried it was worse! Txp only generated the first handful of thumbs – like, 5 or 6, due to lazy loading, and when I scrolled down the page, the rest remained unrendered. But for some reason when I tried it a second time, it rendered them all so maybe something was still cached somehow. Nope, scratch that. I was at the bottom of the page. When I scrolled up, the thumbnails out of viewport didn’t get rendered.

However, a 307 or 302 and TTL=0 is better. Presumably that will refetch them every request, right, so invalidating any browser cache?

Last edited by Bloke (Today 20:11:38)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#243 Today 20:20:01

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,263
Website GitHub

Re: Automatic thumbnails for Textpattern

I did have some weirdness a moment ago. When I navigated to page 2 on the Images panel, none of the thumbs were regenerated. I had to force refresh. After that, when I visited page 2 after clearing the cache, the thumbs were regenerated. My best guess is that the entire page 2 was in the browser cache and it thought nothing had changed so it never hit the server at all.

Side annoyance: Using Ajax pagination means it’s no longer possible/easy witout hacking the URL to pass links around that go to specific pages of results. If I navigate to page 2 of the Images panel results and hit Refresh, it dumps me back on Page 1 because that’s what the URL dictates. It was much better when the URL had the ?pg= and/or ?q= in it

*sigh* That’s progress I guess.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#244 Today 20:20:11

etc
Developer
Registered: 2010-11-11
Posts: 5,633
Website GitHub

Re: Automatic thumbnails for Textpattern

Yep, I have unset cache-control header, leaving it with the browser, please retest. No need for TTL=0 a priori.

Offline

#245 Today 20:21:41

etc
Developer
Registered: 2010-11-11
Posts: 5,633
Website GitHub

Re: Automatic thumbnails for Textpattern

Bloke wrote #341839:

My best guess is that the entire page 2 was in the browser cache and it thought nothing had changed so it never hit the server at all.

I bet yes, but this is not thumbnails-specific.

Offline

#246 Today 20:46:30

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,263
Website GitHub

Re: Automatic thumbnails for Textpattern

That’s much better on localhost. But on my server (front-end and back-end) I get some missing images on refresh. I have to force refresh to get them all to show.

And after I delete the cache, I need to force refresh again to get them all to show up. Random pictures down the page just don’t load and the Inspector reports “Could not load this image”. Here’s a typical request:

GET /images/thumb/w180-h150-c4x3.topcentered-q80-baa3071/186.jpg HTTP/2
Host: example.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:146.0) Gecko/20100101 Firefox/146.0
Accept: image/avif,image/webp,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5
Accept-Language: en-GB,en;q=0.5
Accept-Encoding: gzip, deflate, br, zstd
Referer: https://example.com/textpattern/index.php?event=image
Connection: keep-alive
Cookie: PHPSESSID={key-here}
Sec-Fetch-Dest: image
Sec-Fetch-Mode: no-cors
Sec-Fetch-Site: same-origin
If-Modified-Since: Fri, 19 Dec 2025 20:33:12 GMT
Priority: u=4, i
TE: trailers

And response headers:

HTTP/2 200 
cache-control: no-cache, no-store, max-age=0
vary: Accept-Encoding
content-encoding: br
content-length: 1
content-type: text/html; charset=utf-8
date: Fri, 19 Dec 2025 20:34:15 GMT
server: Apache
X-Firefox-Spdy: h2

The inspector reports it sent 289 bytes back to me. Hardly a full image 🤔

Interestingly, if I copy one of the “broken” thumbnail URLs with its ?token= and paste it into a new browser tab and hit Enter, it immediately redirects to the non-tokenised version, which of course fails to load because the token has been omitted and the system thinks I’m hacking. If I turn off security, all images load, on both admin and public sides.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#247 Today 20:57:46

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,263
Website GitHub

Re: Automatic thumbnails for Textpattern

As an aside, can I just say I’m impressed with the smart cropper. I’ve no idea how the (complex) voodoo inside the class works but if you download this sample set of landscape/portrait images, try this:

  1. In your Admin Theme prefs, set your thumbs to 240 x 200 with a crop = 4x3.
  2. Visit your Images panel and upload some of the Portrait images from that set.
  3. Note the auto-generated thumbnails are centered, with the number slap bang in the middle and the boy’s torso visible. Because centered crop is default.
  4. Revisit your Admin Theme prefs and change the crop value to 4x3:smart.
  5. Return to your Images panel and look at the thumbs it regenerates. Note the boy in the pic is now the main focus, and the number is towards the top of the image.

Very cool for automatic art direction! It’s not perfect, but (if it can find a subject) it makes a pretty good guess where it is.

Other samples that work quite well:

  • https://i.guim.co.uk/img/media/56401d46ac5c87229e10c49540e51c578d95a797/0_50_5760_3456/master/5760.jpg?width=1200&height=1200&quality=85&auto=format&fit=crop&s=4272fffa94a419318d6a4d9ff98965b1
  • https://fujilove.com/wp-content/uploads/2018/07/Figure-in-the-landscape-09.jpg
  • https://filmphotographyjournal.weebly.com/uploads/2/8/0/9/28093007/3040094_orig.jpg

Last edited by Bloke (Today 21:25:33)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#248 Today 21:23:35

etc
Developer
Registered: 2010-11-11
Posts: 5,633
Website GitHub

Re: Automatic thumbnails for Textpattern

Bloke wrote #341842:

Interestingly, if I copy one of the “broken” thumbnail URLs with its ?token= and paste it into a new browser tab and hit Enter, it immediately redirects to the non-tokenised version

Seemingly, your browser has decided to keep 307 redirect in cache for some time. What if you set

'Cache-Control' => 'no-store, no-cache, must-revalidate, max-age=0'

in serveRenderedImage()?

Offline

Board footer

Powered by FluxBB