Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#256 2025-12-20 16:54:04

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

Re: Automatic thumbnails for Textpattern

I don’t anticipate there to be a problem but just in case there’s some server config or browser out there that steadfastly refuses to play by the rules, people will get missed thumbs or white screens with no explanation. At least with a conditional constant, they can turn off the redirect behaviour and know the images will always be generated without the redirect layer getting in the way.

If we get no reports of any issues, we can deprecate the constant and remove it in a future release.


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

#257 2025-12-20 17:14:09

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

Re: Automatic thumbnails for Textpattern

Works for me. The values of THUMB_REDIRECT might be 0, 301, 302 etc, for extra flexibility?

Offline

#258 2025-12-20 17:17:54

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

Re: Automatic thumbnails for Textpattern

I did actually consider that. I think that might be even cooler. I even had random notion that its value might be the cache-control header tags so you could choose how invasive the cache should be. But figured there was probably too much to potentially go wrong.

Question: if we go with allowing a redirect value, should it silently skip any invalid value that isn’t in the 300-range? Wouldn’t want anyone serving a 500 there!


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

#259 2025-12-20 18:02:53

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

Re: Automatic thumbnails for Textpattern

Caveat utilitor?

I’m stuck trying to output automatic thumbnails via, say, <txp:article_image thumbnail />, which is supposed to output thumbnails (or images themselves if none) with correct height/width. The problem is, automatic thumbnails have no ‘default’ dimensions (or, rather, they are admin-theme-dependent). Dunno what would be natural candidates..?

Offline

#260 2025-12-20 18:18:59

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

Re: Automatic thumbnails for Textpattern

etc wrote #341857:

Caveat utilitor?

Hehe, maybe. I’ve errred on the side of caution for now.

I’m stuck trying to output automatic thumbnails via, say, <txp:article_image thumbnail />, which is supposed to output thumbnails (or images themselves if none) with correct height/width. The problem is, automatic thumbnails have no ‘default’ dimensions (or, rather, they are admin-theme-dependent). Dunno what would be natural candidates..?

Convention.

If you specify valueless thumbnail attribute (or a specific value type 0, 1, 2) and the thumbnail type for the current image matches:

  • 1, serve the NNt.ext file at the thumb_w/thumb_h. It squishes or scales (even if pixellated) if you specify your own width / height attributes. If you empty the width / height attributes, it doesn’t output the empty dimension(s) in the tag. crop attribute does nothing.
  • 2, serve the full size image. Auto thumbnails MUST have a width / height / crop or they make no sense.
  • 2 AND you specify a width / height / crop attribute value, serve the auto thumbnail at those dimensions/crop.

EDIT: Or, if you feel we should use a default value for the second case, we have TEXTPATTERN_THUMB_WIDTH and TEXTPATTERN_THUMB_HEIGHT constants, which you could use as fallback? That might make more sense, maybe? They were designed for use on the admin side, but they could apply equally well to the public site as defaults.

Last edited by Bloke (2025-12-20 18:28:01)


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

#261 2025-12-20 18:35:00

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

Re: Automatic thumbnails for Textpattern

Sorry, I made multiple edits / addendums to the previous post :/


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

#262 2025-12-20 18:35:38

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

Re: Automatic thumbnails for Textpattern

Ah, great, thanks! Must be ready in an hour or two.

Offline

#263 2025-12-20 18:36:58

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

Re: Automatic thumbnails for Textpattern

Thank you. I don’t mind which way we play case #2. Either serve full size, or serve it thumbnailed with the constant fallback dimensions.


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

#264 2025-12-20 18:59:16

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

Re: Automatic thumbnails for Textpattern

Answering my own question after doing some online research, I’ve applied the sharpness filter to WebP images by default too. Seems the general feel out in webland is it’s a good idea. But not for AVIF.

I haven’t added an option to choose sharpness or not per image type. Tempted to leave it as-is for now.


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

#265 2025-12-20 21:55:19

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

Re: Automatic thumbnails for Textpattern

jakob wrote #341714:

the behaviour is ever so slightly different between the two with respect to whether the height attribute is shown.

Must be consistent now, please test.

Offline

#266 2025-12-20 22:41:38

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

Re: Automatic thumbnails for Textpattern

etc wrote #341863:

Must be consistent now, please test.

Nice consolidation and sooo close! A few questions:

How do we output custom thumbs at their natural (database) thumb_w + thumb_h? That was done before by omitting width and height (umm, I think, can’t remember). It always seems to use the fallbacks now, afaict.

What does valueless width and/or height do now? What should it do? Ditto width="" – did that ever do anything? Does it do something now?

Can we still use width="0" / height="0" to omit the value from the tag?

Can you check what happens if a thumb doesn’t exist? Previously, if a thumb didn’t exist for whatever reason, it didn’t output anything. Now it outputs an empty <img src="" alt=""> tag. Try downloading the extra large sample image and upload that 15MB monster. Txp fails to make a thumb of it (out of memory error in SLIR). If you add that ID as one of your Article Image fields, my expectation would be for it to not render the thumbnail… umm, right? Or is it better to show that it’s broken, like you have now, by outputting an empty rectangle?

I’ve not gone through all the differences yet. Those were the most obvious ones.

Last edited by Bloke (2025-12-20 22:44:59)


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

#267 2025-12-20 22:58:28

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

Re: Automatic thumbnails for Textpattern

Bloke wrote #341864:

How do we output custom thumbs at their natural (database) thumb_w + thumb_h? That was done before by omitting width and height (umm, I think, can’t remember). It always seems to use the fallbacks now, afaict.

<txp:article_image thumbnail />
<!-- Ah, wait -->

What does valueless width and/or height do now? What should it do? Ditto width="" – did that ever do anything? Does it do something now?

Valueless width/height preserves the natural dimensions, if you ever need it:

<txp:article_image height="200" width />

Without width, the width would be omitted. That’s different from 4.8, where you need to set width="0" to omit it, but I can not see why anyone would like to deform an image.

Can we still use width="0" / height="0" to omit the value from the tag?

Yes, but it will be omitted by default anyway if some other transform is set.

TBC

Offline

#268 2025-12-20 23:10:24

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

Re: Automatic thumbnails for Textpattern

Bloke wrote #341864:

Can you check what happens if a thumb doesn’t exist? Previously, if a thumb didn’t exist for whatever reason, it didn’t output anything. Now it outputs an empty <img src="" alt=""> tag. Try downloading the extra large sample image and upload that 15MB monster. Txp fails to make a thumb of it (out of memory error in SLIR). If you add that ID as one of your Article Image fields, my expectation would be for it to not render the thumbnail… umm, right? Or is it better to show that it’s broken, like you have now, by outputting an empty rectangle?

You mean auto thumbnails? The tag has no means to check whether txp has failed to make a thumbnail or never tried. Previously, if you called

<txp:article_image thumbnail=1" />

the tag loaded only images with thumbnail="1" in the db, but never checked whether 123t.jpg really exists.

Offline

#269 2025-12-20 23:10:34

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

Re: Automatic thumbnails for Textpattern

etc wrote #341865:

Valueless width/height preserves the natural dimensions, if you ever need it

Perfect. That’s what I expect it should do, thank you. I was just checking, cos my test tags are a mess and my brain’s fried.


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

#270 2025-12-20 23:13:45

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

Re: Automatic thumbnails for Textpattern

etc wrote #341866:

You mean auto thumbnails?

Well, either I guess.

But yes you’re right, if the thumb can’t be created on the admin side, it won’t be able to be created on the public site either, so it’ll just fail when SLIR is invoked. So yeah, that’s fine. We’ll take the hit on it outputting a blank tag. Totally cool.


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

Board footer

Powered by FluxBB