Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#181 Yesterday 14:23:28

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

Re: Automatic thumbnails for Textpattern

Callbacks added:

  1. (by ref) txp.image / thumbnail.params is passed the $params array and $thumbnail (the type: 0, 1, or 2) so plugins can take action only on a certain type of thumbnail access, or can inject parameters for fullsize images too.
  2. txp.image / url / thumbnail is passed the current URL, the image object, the $params, and $thumbnail (the latter in case you want to switch on it without having to add individual handlers for each type of thumbnail).

I did some rudimentary tests and it gives some nice powers to plugins to play with the generated thumbs, and to change things.


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

#182 Yesterday 14:28:30

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

Re: Automatic thumbnails for Textpattern

etc wrote #341752:

It complains about type mismatch.

That’ll probably be because of the SLIRImageLibrary interface, which will also need its signature changing.

The out of memory is probably due to a large source image. It’s not very robust with big files, which is something we can look at later. I managed to max out my hosts’ maximum 256MB php.ini setting generating a thumb on a smallish 3000px square image.

As long as it works for now, on regular size (not HD) pics, we can refine it and optimise it in future. Unless you happen to know some memory-saving tricks when creating thumbs (because class.thumb.php manages it on largish pics so we might be able to copy code over).


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

#183 Yesterday 15:59:39

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

Re: Automatic thumbnails for Textpattern

Okay, I reverted the transparency tweaks I made since they broke the ability for /w400-b0e56ae/NN.ext style URLs to add backgrounds to transparent images.

I guess the patch they supplied wasn’t battle tested (or I misinterpreted it, but I did try it a few ways, including directly copying it over in case my tweaks broke it). Neither worked, so we’ll rethink 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

#184 Yesterday 18:42:13

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

Re: Automatic thumbnails for Textpattern

Thanks for all your investigations and updates. I just a did a test with the transparent images I tested before plus Philippe’s image, and then with the example exif images linked to above. Findings:

  • All static transparent images rendered for me with a transparent background, including Philippe’s screenshot image.
  • Animated transparent images show a black background. This is probably a special case where animated images are concerned.
  • Quality settings seem to work. The corresponding thumbs are created. In my test image I couldn’t accurately see the difference between quality="50" and quality="100", but an image diff does show they are indeed different.
  • Testing the exit examples linked to above: all images are correctly rotated, but images 5, 6, 7 & 8 all have a cropped thumbnail in both orientations. The portrait images have a dark band to the right for the portrait images, and along the bottom for the landscape images, and a bit of the image is cropped off. See the screenshot (source of the test images).

TXP Builders – finely-crafted code, design and txp

Offline

#185 Today 01:29:59

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

Re: Automatic thumbnails for Textpattern

Hmmm, I can’t fathom the best place to apply this fixRotation() method. In the position it is now, it does the job but the info object seems to be overwritten. Or it just doesn’t apply the value (I can’t tell which).

If I move the function call a bit later, it still makes no difference.

There is an issue with the dimension swapper. It (wrongly) swaps the current image’s dimensions but what it really needs to do is replace the new image’s dimensions with the original image’s dimensions, in reverse. A bit like this:

// Swap height and width values if thumbnail is rotated by 90°.
if (in_array($exif['Orientation'], [5, 6, 7, 8])) {
    $this->setWidth($exif['COMPUTED']['Height']);
    $this->setHeight($exif['COMPUTED']['Width']);
}

That does indeed “work” except the resulting (landscape) image is squished in the X-axis to fit the cropped viewport (if a cropper is applied). Presumably the portrait images will be squishes in the Y-axis.

I don’t know for sure but I suspect this rescaling either needs to take place after we know what cropper is going to be applied, so we can set the wdth and height to the cropped dimensions. Or it needs to use different values – perhaps using the relative scaling factor (see SLIR.php: resizeCroppedWidthFactor()). Or maybe we need to setCropWidth() and setCropHeight() (instead of, or in addition to, the regular width and height)?

Quite what these values should be isn’t clear to me. Might just need a bit of messing around to reverse engineer which fixed values work, and then figure out where to read those values from inside the class.

Bottom line is that we need to replicate what happens in Jools’ patch to class.thumb.php, just using the variable names and image objects from SLIR. The fixRotation() method is close – very close – but the bit that sets the width and height is wrong and I can’t fathom it with the woolly head I have on right now.

If anybody has any insight with fresh eyes, be my guest. Otherwise I’ll try again tomorrow.


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

#186 Today 06:31:20

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

Re: Automatic thumbnails for Textpattern

Testing with the lasted updates, quality and the transparency support (third attempt).

  1. quality: using quality:50 and quality:100, visually it didn’t make much difference for my landscape image, the portrait image (person against cityscape in the distance) there was a little bit of improvement in the sharpness of the face and the product image (product with blurred background) there was a more noticeable edge sharpness. The quality:100 images have a much larger file size as can be expected (2 to 3 times).
  2. transparency: using the Sandspace UI screenshot I shared the other day (.webp format: Yesssir, no more black border! 👍Visual inspection with the macOS screen magnifier show smooth edges all around.

Note: the screenshot above was scaled from 1600px to 800px and displayed at half the size to mimic my monitor’s DPR. That way the image does renders crisply.


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

Offline

#187 Today 11:12:59

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

Re: Automatic thumbnails for Textpattern

Looks like you nailed it. Well done! As you say, the test images work correctly now.

Overall, it’s pretty brilliant now!


TXP Builders – finely-crafted code, design and txp

Offline

#188 Today 11:16:37

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

Re: Automatic thumbnails for Textpattern

[Moved from wrong thread, d’oh]

Aha!

The trick is to split the calculation part that swaps the image dimension at input time, and perform the rotation later at output time. Try that and see how you get on with rotated images. It works for the 18 sample images in that set Jools posted.

It does assume that the Orientation flag is in the root EXIF data structure. I’ve heard rumour that some cameras put it elsewhere (like in the COMPUTED section, maybe?) which will knacker this up. So the more tests we can perform from a wide array of devices, the better.


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

#189 Today 11:18:13

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

Re: Automatic thumbnails for Textpattern

Hah, oops. Idiot. I moved my post and updated your link. Thanks for keeping me sharp!


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

#190 Today 11:39:27

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

Re: Automatic thumbnails for Textpattern

Bear in mind you can alter the cropper used in your Theme Prefs too (and maybe URL, not tried it), as a third argument. And you can split your ratios by dot, colon or ‘x’. You have a choice of three croppers:

  • smart
  • centered
  • topcentered

So, example crop ratios:

  • 1×1
  • 100×150
  • 3×2
  • 16:9
  • 4.3
  • 4.3.topcentered
  • 3×2:centered
  • 16×9.smart

And so on. Please test them and see the difference.


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

#191 Today 13:21:58

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

Re: Automatic thumbnails for Textpattern

Exciting!

We might probably avoid filling/reading txp_token table, unless thumbnail tokens serve yet for something else. What is their exact purpose? Could not we check in some way that the provided ?token=... is valid, without assuming that it is written to txp_token via imageBuildURL()?

Offline

#192 Today 13:34:40

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

Re: Automatic thumbnails for Textpattern

etc wrote #341776:

We might probably avoid filling/reading txp_token table, unless thumbnail tokens serve yet for something else. What is their exact purpose?

Only to check that the request originated from a tag or the admin side. That’s all.

If you have any better ideas for implementations, by all means go for it.

The goal is simply to stop anyone spamming the URL and creating a zillion images, filling up disk space and consuming processor resources.

How that is implemented, I have no preference.


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

Board footer

Powered by FluxBB