Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#181 Yesterday 14:23:28
Re: Automatic thumbnails for Textpattern
Callbacks added:
- (by ref)
txp.image/thumbnail.paramsis passed the$paramsarray 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. txp.image/url/thumbnailis 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
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
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
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"andquality="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
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
Re: Automatic thumbnails for Textpattern
Testing with the lasted updates, quality and the transparency support (third attempt).
- quality: using
quality:50andquality: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. Thequality:100images have a much larger file size as can be expected (2 to 3 times). - transparency: using the Sandspace UI screenshot I shared the other day (
.webpformat: 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