Basic thumbnail usage with toolkit only?

I have been fiddling around with the toolkit - without cms - and i couldn’t figure out how to use it. The documentation for the toolkit is jsut still very basic so i assumed someone here might be of help.

While kirby cms takes all the things away ( setting thumbnail folder and whatsoever ) with the toolkit only i guess it’s more than just using

<?php echo thumb($page->image(), array('width' => 300)) ?>

Yes and no. The toolkit contains all the necessary code, but you need to configure it. The options are defined in the Thumb class and you can override them using the second parameter of thumb().
Relevant in your case is root and url, which should be set to your file system and web server paths.

Hi @lukasbestle,

Even with the correct paths set in the Thumb class i still cant get this to work when using the toolkit only.

looking at the toolkit docs you have thumb::get($key, $default = null), would this have to be used or could you call the thumbs by using thumb(…);

cheers!

The thumb() helper is not part of the toolkit.

OK, that’s fine. How would you go about calling a thumb from just the toolkit?

You would have to create a new thumb instance

$thumb = new Thumb($source, $params);

Where $source is either a path to a file or a Media object, and $params are the configuration parameters. You’d best be checking the source code of the Thumb class.

Cheers Sonja,

I’m still not getting the correct output though, can you help?

   <?php
       $thumb = new Thumb('panel' . DS . 'uploads' . DS . $media->media_filename(), array(
           'width'  => 300,
           'height' => 400,
       ));
   ?>

The above is my code, it’s pulling out the saved filename from a database, the thumbs directory has been changed to uploads and is found at

 /panel/uploads

if i dump out $thumb i’m returned an object which shows all the information below, notice there is no url. ive also tried a variation of thumb/uploads folders but having no luck.

 Thumb Object
 (
[source] => Media Object
    (
        [root] => 
 C:\xampp\htdocs\planetreference\panel\uploads\12828480_10156678780965565_1172406654197147164_o.jpg
        [url] => 
        [hash] => d65deb89ca81086dabcebcee49d28e7b
        [dir] => C:\xampp\htdocs\planetreference\panel\uploads
        [filename] => 12828480_10156678780965565_1172406654197147164_o.jpg
        [name] => 12828480_10156678780965565_1172406654197147164_o
        [safeName] => 12828480_10156678780965565_1172406654197147164_o.jpg
        [extension] => jpg
        [size] => 163460
        [niceSize] => 159.63 kB
        [modified] => 2017-05-05T16:17:07+02:00
        [mime] => image/jpeg
        [type] => image
        [dimensions] => Dimensions Object
            (
                [width] => 2048
                [height] => 1536
                [ratio] => 1.3333333333333
                [orientation] => landscape
            )

        [isWritable] => 1
        [isReadable] => 1
        [isExecutable] => 
        [header] => Content-type: image/jpeg
        [exif] => Exif Object
            (
                [camera] => Exif\Camera Object
                    (
                        [make] => 
                        [model] => 
                    )

                [location] => Exif\Location Object
                    (
                        [lat] => 
                        [lng] => 
                    )

                [timestamp] => 1493993827
                [exposure] => 
                [aperture] => 
                [iso] => 
                [focalLength] => 
                [isColor] => 1
            )

    )

     [result] => Media Object
    (
        [root] => 
 C:\xampp\htdocs\planetreference\panel\uploads\12828480_10156678780965565_1172406654197147164_o.jpg
        [url] => panel/uploads/12828480_10156678780965565_1172406654197147164_o.jpg
        [hash] => d65deb89ca81086dabcebcee49d28e7b
        [dir] => C:\xampp\htdocs\planetreference\panel\uploads
        [filename] => 12828480_10156678780965565_1172406654197147164_o.jpg
        [name] => 12828480_10156678780965565_1172406654197147164_o
        [safeName] => 12828480_10156678780965565_1172406654197147164_o.jpg
        [extension] => jpg
        [size] => 163460
        [niceSize] => 159.63 kB
        [modified] => 2017-05-05T16:17:07+02:00
        [mime] => image/jpeg
        [type] => image
        [dimensions] => Dimensions Object
            (
                [width] => 2048
                [height] => 1536
                [ratio] => 1.3333333333333
                [orientation] => landscape
            )

        [isWritable] => 1
        [isReadable] => 1
        [isExecutable] => 
        [header] => Content-type: image/jpeg
        [exif] => Exif Object
            (
                [camera] => Exif\Camera Object
                    (
                        [make] => 
                        [model] => 
                    )

                [location] => Exif\Location Object
                    (
                        [lat] => 
                        [lng] => 
                    )

                [timestamp] => 1493993827
                [exposure] => 
                [aperture] => 
                [iso] => 
                [focalLength] => 
                [isColor] => 1
            )

    )

[destination] => Obj Object
    (
        [filename] => 12828480_10156678780965565_1172406654197147164_o.jpg
        [url] => panel/uploads/12828480_10156678780965565_1172406654197147164_o.jpg
        [root] => panel/uploads\12828480_10156678780965565_1172406654197147164_o.jpg
    )

[options] => Array
    (
        [destination] => 
        [filename] => {safeName}.{extension}
        [url] => panel/uploads
        [root] => panel/uploads
        [driver] => im
        [memory] => 128M
        [quality] => 90
        [blur] => 
        [blurpx] => 10
        [width] => 300
        [height] => 400
        [upscale] => 
        [crop] => 1
        [grayscale] => 
        [overwrite] => 
        [autoOrient] => 
        [interlace] => 
    )

[error] => 
 )   

i suspect its something basic but still missing it.

for clarity i’ve also set the root and url to both panel/uploads and panel/thumbs

Regards

Chris

Hm, I’ve never tried that myself, but I suspect that when you create the media object, you probably do not pass a URL? Have a look at the media class constructor.

I’ve invited @lukasbestle to this topic as I don’t have the time to test this now.

The Media object does not need to have a URL param set for the thumb to be generated.

Could you please try if it works if you set the root option to an absolute path to the directory (with __DIR__, DS and the dirname() function you can build the path dynamically)? Because you are on Windows, there might be an issue with the directory separators.
Please also try if you can generate thumbs using the Kirby CMS on the same computer. It might also be that ImageMagick isn’t installed properly.

Hi Lukas,

I’ve tried setting the path to an absolute path using DS etc but still no joy. I’m now just getting a message warning the image file is not valid. I’m using the same environment that I use for all my Kirby work which is generating thumbs just fine.

At present I’m overriding the root URL in the params array and also including just the image path as the source.

Still no joy. no thumbs being generated and apparently not a valid image file.

Am i correct that i should be able to take the image url saved in a mysql database and return that as a thumb if the paths are correct?

Could you please post the full error message including the tracelog?

You need to have the image locally. Just passing Kirby a URL to the image won’t work, you need to download it first if it’s on an external server.

Hi Lukas,

The image is uploaded to a folder using the toolkit, i’m attempting to generate a thumbnail of this image when uploaded.

There is a page that then (hopefully) displays all thumbnails for the images saved into the database. Does this make sense?

I believe it is a image source issue since it returns an error pertaining to line 68 in the toolkit class. (The given image is invalid).

Could you please post the full error as I wrote above?