Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#169 Today 00:55:50

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

Re: Automatic thumbnails for Textpattern

jakob wrote #341734:

this fix in a fork any help perhaps?

I fully expect so. We should roll that change in and see if it fixes anything. Then worry about doing the same for the other transparent formats.

Good find, thank you.


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

#170 Today 00:59:41

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

Re: Automatic thumbnails for Textpattern

Btw, I fixed the garbage collector but haven’t (yet) exposed the timeout length to config.php. I’ll do that in the morning.

In the meantime, if you want to test this to check stuff gets deleted with short expiration times you’ll have to hack the SLIRConfigDefaults.php file and set the cache time to some number of seconds you want to test.

Bear in mind the collector only runs on a percentage basis so you might also want to increase the numerator value in the config file too (it’s documented well).


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

#171 Today 10:01:35

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

Re: Automatic thumbnails for Textpattern

I just fixed a few little oversights with the original SLIR code. For starters, transparency was only available for GIF and PNG. I’ve extended that to WebP and AVIF now too, ready for applying the patch that Jools found on that other fork.

I’m just looking into the rotation issue. It seems, on the surface, that we can broadly copy the processing that class.thumb does in this regard. I’ve just got to find the best place in the code to apply it.

Moving on, I have a question. Currently, when you upload a JPG, it applies a sharpness filter to the thumbnail (the sharpening factor is determined automatically based on the size of the source vs destination image areas). Should this automatic sharpening be applied to any other formats? I could extend it to WebP by changing one line of code. Same with AVIF (I presume sharpening doesn’t hold much value for lossless formats like GIF and PNG). Or are the results at the moment for WebP and AVIF files suitable?

If you would like to have a go at it yourself to compare, change the line (currently 371) in isSharpeningDesired() (SLIRImage.php) to include the formats you want to sharpen. So, for example, change:

        if ($this->isJPEG()) {

to:

        if ($this->isJPEG() || $this->isWEBP() || $this->isAVIF()) {

if you want to apply the sharpness filter to all three formats.


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

#172 Today 10:20:53

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

Re: Automatic thumbnails for Textpattern

Okay, thumbnail image rotation should be fixed if the EXIF data dictates. The code is lifted directly from class.thumb.php, and that’s been working for ages, so it shouldn’t pose any issues. Please test.


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

#173 Today 10:45:10

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

Re: Automatic thumbnails for Textpattern

Bloke wrote #341737:

Currently, when you upload a JPG, it applies a sharpness filter to the thumbnail

I’m also considering adding a config option to turn this off. Does that have value? Or is it desired to always apply a sharpness filter to thumbs in whatever formats we determine need them?


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

#174 Today 10:59:53

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

Re: Automatic thumbnails for Textpattern

jakob wrote #341734:

this fix in a fork

I’m torn here. The original transparency fix introduced the $transparencyEnabled flag and tests it. The fix in the forked library completely removes the flag and applies the alpha regardless to all images.

I did some research and, apparently:

When you use imagecolorallocatealpha() on an image that will eventually be saved as a JPEG, the alpha channel information will be lost, and transparent areas will typically default to a solid background color (usually black or white)

So I’m not entirely sure how that will play out if we ultimately allow conversion between types (e.g. load up a transparent AVIF and squirt it out as a JPEG). I suspect a yucky solid black background will be rendered if we apply that patch verbatim.

My gut feel is to meet these patches in the middle. i.e. apply the transparency to the destination image but also retain the flag so we can decide whether to take action later. Anyone have any insight on this?


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

#175 Today 11:20:20

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

Re: Automatic thumbnails for Textpattern

Bloke wrote #341739:

I’m also considering adding a config option to turn this off. Does that have value? Or is it desired to always apply a sharpness filter to thumbs in whatever formats we determine need them?

I think that yes, the sharpness filter holds some value. Depending on the subject the image (view out of my window vs portrait of my grandmother vs a product photo) the .webp results are quite reasonable (case 1) to a little too blurry (case 3). That depends too on the scaling factor. A config option might be useful too.

(to make it a little more complicated: it depends on the format .webp scales some better than .jpg)


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

Offline

#176 Today 12:43:22

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

Re: Automatic thumbnails for Textpattern

Just had a second attempt at transparency. Some of the sample images I tried (e.g. smoky cyan wispy thing) rendered black backgrounds using the patch from that other fork, so I’ve tweaked it again. Please test.

I’ve also just exposed a new tag attribute quality. It’s only of use on thumbnails (of course) and on image types that support it, but it allows you to specify a value between 1-100 to alter the auto thumbnail quality.

Custom thumbs and the automatically-created ones visible on the admin side are always rendered at the quality value specificed in TEXTPATTERN_THUMB_QUALITY (overridable in config.php). No sanitization of that is done so if you make a mess of it, you’ll get no thumbs.


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

#177 Today 13:29:10

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

Re: Automatic thumbnails for Textpattern

Got this, but I’m not sure how to patch it in php 5 compatible way:

General error 8192: lencioni\SLIR\libs\gd\SLIRGDImage::enableTransparency(): Implicitly marking parameter $destination as nullable is deprecated, the explicit nullable type must be used instead on line 356

Fixing it (php 8.5) makes things worse:

<b>Fatal error</b>:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 16384 bytes) in <b>...\textpattern\vendors\lencioni\SLIR\libs\gd\SLIRGDImage.php</b> on line <b>673</b>

Offline

#178 Today 13:35:58

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

Re: Automatic thumbnails for Textpattern

enableTransparency(SLIRImageLibrary $destination = '')

??


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

#179 Today 13:37:47

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

Re: Automatic thumbnails for Textpattern

It’s not applying a background colour at the moment. Like, at all. I’ve just added some callbacks and testing a plugin to alter the parameters. It’s injecting them just fine, the fill() method runs but… doesn’t add the background colour for some reason. Baffling.


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

#180 Today 14:18:29

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

Re: Automatic thumbnails for Textpattern

Bloke wrote #341750:

enableTransparency(SLIRImageLibrary $destination = '')...

It complains about type mismatch. I have removed the type hint and added $destination instanceof SLIRImageLibrary check, but the weird out of memory issue persists, weirdly only public side.

Offline

Board footer

Powered by FluxBB