Hi everyone,
I encounter issues with the Toolkit thumb function in a custom Kirby-tag. As I mention it in the post title, the function seems unable to save images when panel and templates can.
I don’t understand if I don’t use the function correctly or if it’s a server configuration problem. But from a server configuration point of view, it seems OK, because the thumb folder is not empty.
My function is
$_thumb = new Thumb($file->root(), array(
'driver' => 'gd',
'width' => $tag->attr('width') ?: c::get('kirbytext.image.width', null),
'height' => $tag->attr('height') ?: c::get('kirbytext.image.height', null),
));
This function does not create new files in the thumb folder.
I tried with and without gd
driver (im
by default, kirby/toolkit/lib/thumb.php
line 24)
With im
, I cannot output anything, with gd
, I can see an error if I add echo $e;
on line 363 of kirby/toolkit/lib/thumb.php
(I did not manage how to use thumb::error()
).
Any help appreciates.
Thanks,
j.
OK,
I just had to set a root
option because default is set to /thumbs
(and it’s from the root of your server).
$_thumb = new Thumb($file, array(
'driver' => 'gd',
'root' => kirby()->roots()->thumbs(),
'width' => $tag->attr('width') ?: c::get('kirbytext.image.width',null),
'height' => $tag->attr('height') ?: c::get('kirbytext.image.height',null),
));
1 Like
Hum, a strange thing appends.
My function is in Kirby tag.
If I use it like this, the created thumbnails are named and organized like the old fashion flat-hashed way.
Don’t change anything, but use a $anotherImage->resize($width)
somewhere
before in the template, and the Kirby tag thumbnails are properly
renamed and organized like 2.3. do.
Why? Is the resize()
method defines some global parameters I missed?
Thanks,
j.
With Kirby 2.3, the CMS-specific thumb code has been moved from the Toolkit to a new thumb
component. The Thumb
class is now more low-level.
You can use the CMS-specific code if you use the thumb()
helper instead of new Thumb
.
1 Like
Thank you @lukasbestle! It works like a charm!
You can find its application here : https://github.com/julien-gargot/kirby-plugin-auto-thumbnail.
Cheers