Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: Automatic thumbnails for Textpattern
etc wrote #341621:
Mined area. I’ve made some changes like this in 4.8.8… to discover that empty
widthis used more often than expected, so 4.9 restores (?) the 4.8.7 behaviour.
Not sure. I don’t want to trample too much old code. But if you don’t specify you want to see a thumbnail (i.e. you expect the full image because you’ve not supplied any attributes to the contrary) it’s counterintuitive to see a scaled version just because you have made a physical thumbnail… isn’t it?
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
Re: Automatic thumbnails for Textpattern
I created a bunch of tests using an Article Image field with a range and some random images of different types (10-17, 36, 34, 6):
<txp:if_article_image>
<h3>Full article image</h3><txp:article_image /><br>
<h3>Full zero width article image</h3><txp:article_image width="0" /><br>
<h3>Scaled fullsize article image</h3><txp:article_image width="400" /><br>
<h3>Article image thumbs (default)</h3><txp:article_image thumbnail range /><br>
<h3>Scaled article image thumbs (default)</h3><txp:article_image thumbnail range width="400" /><br>
<h3>Custom article image thumbs (forced)</h3><txp:article_image thumbnail="1" range /><br>
<h3>Custom scaled article image thumbs (forced)</h3><txp:article_image thumbnail="1" range width="400" /><br>
<h3>Auto scaled article image thumbs (forced)</h3><txp:article_image thumbnail="2" range width="300" /><br>
<txp:images>
<h3>Full image</h3><txp:image />
<h3>Full zero width image</h3><txp:image width="0" />
<h3>Scaled fullsize image</h3><txp:image width="300" />
<h3>Thumb (default)</h3><txp:image thumbnail />
<h3>Scaled thumb (default)</h3><txp:image thumbnail width="250" />
<h3>Custom thumb (forced)</h3><txp:image thumbnail="1" />
<h3>Custom scaled thumb (forced)</h3><txp:image thumbnail="1" width="250" />
<h3>Auto scaled thumb (forced)</h3><txp:image thumbnail="2" width="200" />
</txp:images>
</txp:if_article_image>
The results seemed fairly consistent after applying the latest patch.
Is that any more logical, do you think? And does it work for your own tests?
One little irritation: you can’t output exactly the same thumbnail image with exactly the same dimensions/crop more than once on the same page, because the second token overwrites the first and causes it to become invalid. Hence the reason I’ve varied the image sizes throughout.
This isn’t an issue if the security feature is turned off. So, dunno. Depends if we think anyone is likely to want to display the same thumbnail image at the same size multiple times on the same page. Maybe a list view (sidebar) and an individual article_custom on the same page, perhaps? Although would they employ identical sizes in real applications? Hmmm.
Last edited by Bloke (Yesterday 11:59:30)
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
Re: Automatic thumbnails for Textpattern
Bloke wrote #341625:
But it means Nginx can’t play out of the box so we’d need to make this feature Apache only
Dunno. People do run txp on nginx, so a .htaccess equivalent should be possible. It does not even has to be changed, perhaps, because the current rules say ‘if a file exists — grab it, otherwise go txp’. So it would suffice that a thumbnail image had src="images/cache/request/1ef6d72ecd924c5d9b59eeccb5cf7460" (say) to enable the direct access to cached images. And if it does not exist, txp takes the lead and creates it on the fly. Sure, I have not yet groked the security part of this stuff.
Offline
Re: Automatic thumbnails for Textpattern
Sure. Take a look at the .htaccess in the project repo. If you think a physical URL with something like that in it is better, then we can get rid of the pref.
From a security standpoint, the only thing we want to prevent is frivolous generation of cached images by directly hitting the /thumbnaildirectory. Once it’s cached I’m happy to bypass the tokenisation and serve the file directly. That’s how it should work.
It’s actually meant to do that already because I told SLIR to ignore imgtoken so as soon as there’s a cache hit for that, it should fetch the request or prerendered image. Maybe it’s not doing that?
Perhaps if, instead of always generating a token, if a request from a tag results in a cache hit, we just serve the direct image URL as you suggest.
That would also mean multiple hits for the same image on the same page would work because the URL goes direct to the pre-rendered content. I’d be much happier with that.
In theory, SLIR does all that out of the box with the supplied .htaccess (minus Nginx support) but it didn’t work for me. I got internal server errors due to the php_value statements and I have no idea why.
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
Re: Automatic thumbnails for Textpattern
Bloke wrote #341627:
The results seemed fairly consistent after applying the latest patch.
Is that any more logical, do you think? And does it work for your own tests?
Hmm, still a few (what seem to me) anomalies.
For the custom (user-defined) thumbnail, the results are as before except for
<txp:article_image />
which shows the full-size image with
- correct full-size width attribute, but
- thumbnail height attribute (300) <- should this not be the full-size image height?
The automatic thumbnail is still as before. The means I get two non-loaded images for these two cases:
<!-- Render article image(s) as thumbnails scaled to 200px wide.
Use custom thumbs as the source if they exist, otherwise auto-generate them -->
<txp:article_image thumbnail width="200" />
<!-- Render article image(s) as thumbnails scaled to 200px wide.
Force custom thumbs (if they've been created) and scale them -->
<txp:article_image thumbnail="1" width="200" />
The first of those seem to be related to the “same width”-issue you mention above. That’s confirmed if I set the thumbnail to render at a different size.
The second occurs because there is no 9t.jpg image for automatically created images.
Depends if we think anyone is likely to want to display the same thumbnail image at the same size multiple times on the same page […] Although would they employ identical sizes in real applications? Hmmm.
A classic case of that might be a placeholder image.
TXP Builders – finely-crafted code, design and txp
Offline
Re: Automatic thumbnails for Textpattern
Bloke wrote #341625:
The original implementation of SLIR does indeed introduce a custom .htaccess in its own physical directory. If you think that’s better to hard-code it, then cool. But it means Nginx can’t play out of the box so we’d need to make this feature Apache only somehow (i.e. hide the prefs, hide the theme prefs, etc etc). Not sure how we’d handle the security in that case. Rate limits instead of tokens?
No, it’s just great that it works out of the box with nginx.
TXP Builders – finely-crafted code, design and txp
Offline
Re: Automatic thumbnails for Textpattern
I spotted the rogue height value in the output and it was next on my hit list but that won’t be till this evening now. It’s a weird one.
As for the missing thumbnail ‘t’ physical image, yeah, not sure. If you’re forcing your tag to grab the custom thumbnail and it doesn’t exist, what would the desired outcome be?
And ooft placeholders yeah. Okay. That’s gonna need attention so it retrieves and serves the cached version.
Last edited by Bloke (Yesterday 13:14:51)
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
Re: Automatic thumbnails for Textpattern
Bloke wrote #341632:
I spotted the rogue height value in the output and it was next on my hit list but that won’t be till this evening now. It’s a weird one.
👍
As for the missing thumbnail ‘t’ physical image, yeah, not sure. If you’re forcing your tag to grab the custom thumbnail and it doesn’t exist, what would the desired outcome be?
Not sure. I’m wondering about the case of themes people might want to distribute rendering holes. But maybe one wouldn’t use that tag construction at all anymore with the new method.
And ooft placeholders yeah. Okay. That’s gonna need attention so it retrieves and serves the cached version.
I don’t suppose it could ‘sense’ whether an identical thumbnail has already been rendered on a page.
And: THANK YOU!
TXP Builders – finely-crafted code, design and txp
Offline
Re: Automatic thumbnails for Textpattern
jakob wrote #341633:
I don’t suppose it could ‘sense’ whether an identical thumbnail has already been rendered on a page.
It’s meant to be doing that already – whether it’s on the same page or any other future request. That’s the point of the cache! But I suspect it’s not doing it properly, or is still blindly generating a new token.
What we need is for the token to only matter the first time a new thumb is requested. After that, if you ask it for a particular size and it exists, it should just short circuit the lot and grab the file directly. No idea (at present) why it’s not doing that but it’ll be some idiotic mistake on my part that hopefully someone with fresher eyes than mine can spot in a heartbeat.
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
Re: Automatic thumbnails for Textpattern
Could we get this into 4.9.0 with preliminary support, and then flesh it out for full support in 4.9.1? Setting expectations etc.
Offline
Re: Automatic thumbnails for Textpattern
gaekwad wrote #341636:
Could we get this into 4.9.0 with preliminary support, and then flesh it out for full support in 4.9.1? Setting expectations etc.
Definitely. Unless we can’t get the cache working reliably, in a performant manner. In which case I’m perfectly happy to roll back the commits and push this to 5.0
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
Re: Automatic thumbnails for Textpattern
*quivering lip* But, it’s so good!
(Another duplicate image case is sliders or carousels that reload an image to loop a cycle of images)
TXP Builders – finely-crafted code, design and txp
Offline