Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#211 2025-12-18 19:55:41

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

Re: Automatic thumbnails for Textpattern

:)


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

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#212 2025-12-18 19:56:51

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

Re: Automatic thumbnails for Textpattern

I’m tempted to stick with the tokenization we have. I can live with the fact that two identical thumbs get different tokens when each request is atomic anyway, and only used once.


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

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#213 2025-12-18 20:56:28

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

Re: Automatic thumbnails for Textpattern

Well, that was not perfect (yet). Now thumbnail tokens are immutable and used even for existing thumbnails. This way they are not loaded twice, from different URLs.

Offline

#214 2025-12-18 20:58:19

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

Re: Automatic thumbnails for Textpattern

Bah. Is it easily fixable?

I probably screwed something up, cos it was definitely loading them without tokens on refresh when I last checked.


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

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#215 2025-12-18 21:18:25

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

Re: Automatic thumbnails for Textpattern

Are you sure the page was not loaded from cache? Just in case, what dmp(hash_hmac('sha256', 'hello', 'world')); gives?

Offline

#216 2025-12-18 21:52:09

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

Re: Automatic thumbnails for Textpattern

Who knows? Maybe.

If you’ve got time to look at it, that would be ace.


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

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#217 2025-12-18 22:18:07

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

Re: Automatic thumbnails for Textpattern

Sorry, I meant now tokens are always used, even for existing thumbnails.

  • Pros: generated thumbnails are put in browsers cache immediately and used on further access, since their URL remains the same.
  • Cons: when the secret key is changed, URLs change too, so the browser has to download (from disk) the thumbnails again, even if they are already cached.

Dunno which is better. Probably, we could send a 301 redirect to the canonical tokenless URL?

Offline

#218 2025-12-18 22:58:29

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

Re: Automatic thumbnails for Textpattern

Ah okay. hash_hmac() works and is better than faffing with the Token class, imo, and harder to hack than crypt().

I’ll run some tests in a few mins but that seems like a good compromise to me.


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

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#219 2025-12-18 23:31:17

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

Re: Automatic thumbnails for Textpattern

Meanwhile I have reverted existing thumbnails to tokenless URLs. If you want, try adding

global $img_dir;
set_headers(array(1=>301,"Location" => ihu.$img_dir.'/'.TEXTPATTERN_THUMB_DIR.$this->renderedCacheFilename()));
exit;

after l.1450 of SLIR.php. The idea is, once the thumbnail generated, redirect the request to its tokenless URL. This way, the thumbnail is not cached as its temporary URL, but directly as its tokenless URL.

Offline

#220 2025-12-18 23:43:25

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

Re: Automatic thumbnails for Textpattern

Yeah, that totally works for me. I like it. Fast. Predictable. Secure. Ticks all the boxes. Nice work, thank you.

And thanks to everyone who has indulged me these past few weeks with testing and ideas and code and pointers as we turn my crazy last-minute idea into something I hope will be of huge benefit to the Txp community.

I’ve been mulling this over for months and months, trying stuff, rejecting it, trying something else, trying it as a plugin, etc etc. My original reticence at bringing this to core was because I couldn’t figure how to offer both the auto-thumb generation and changing the tags to support regular images, srcsets, art direction and so forth.

Then it hit me: why bother doing everything? The tags are flexible enough to DIY, so just provide the engine and let site admins use the tags to build the bodywork. And here we are.

Let the last minute testing commence! Not just this feature, but everything you can, please. New installs, upgrades, SMTP features, future and ancient content dates, UI library, as many tag features as you can, user management, plugins, whatever you can lay your hands on would be of immense benefit.

Then let’s lock the branch tomorrow night and pull the chocks to launch this magnificence.


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

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#221 2025-12-18 23:44:49

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

Re: Automatic thumbnails for Textpattern

etc wrote #341809:

The idea is, once the thumbnail generated, redirect the request to its tokenless URL. This way, the thumbnail is not cached as its temporary URL, but directly as its tokenless URL.

Neat idea. I’ll add that now and see what happens.


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

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#222 2025-12-19 00:00:48

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

Re: Automatic thumbnails for Textpattern

Okay, that works fine on a server but borks on localhost. Like, it sits there for 5 seconds or so with a broken/empty image placeholder space and then, eventually, the 301 redirects and the content loads. No idea why.


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

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#223 2025-12-19 00:09:38

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,199
Website GitHub

Re: Automatic thumbnails for Textpattern

I’ve just tried clearing caches and the contents of the thumbs folder, then reloading. The very first time I got some dropped out images but the images were generated. I couldn’t see why they weren’t appearing. But I haven’t been able to provoke that into happening again, logged-in or not, with completed cleared browser cache and folder, with a new browser. Seems to work just fine on localhost. The tokens for identical sized images also match.

User passwords, activation links, password resets work in quick local testing too. I can do more testing tomorrow…


TXP Builders – finely-crafted code, design and txp

Offline

#224 2025-12-19 00:24:19

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

Re: Automatic thumbnails for Textpattern

Okay, thank you. Tell you what, I’ll commit this 301 redirect change and see what the fallout is. We can always revert in the morning.

It appears I’m not alone with the 5-second thing…

ibb.co/PGjTZ3Nc

Gimma a few mins to commit it.

EDIT: Done

Last edited by Bloke (2025-12-19 00:28:09)


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

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#225 2025-12-19 00:48:23

phiw13
Plugin Author
From: South-Western Japan
Registered: 2004-02-27
Posts: 3,643
Website

Re: Automatic thumbnails for Textpattern

The image handling is still working fine here, and it feels blazing fast. Tested with all /images/thumb/* folders removed and the browser caches et tutti quanti cleared.

I do not see the localhost delay so far.

Great work with this.


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
phiw13 on Codeberg

Offline

Board footer

Powered by FluxBB