ImageMagick thumbs additional function

Hi
I would like to use an ImageMagick function, how to use it ? I’ve already installed ImageMagick on Mamp.
Do I have to start a new plugin file to set this function ? How to make it work correctly ?

function oilPaintImage($imagePath, $radius)
{
    $imagick = new \Imagick(realpath($imagePath));
    $imagick->oilPaintImage($radius);
    header("Content-Type: image/jpg");
    echo $imagick->getImageBlob();
}

I don’t know how to implemante it into these lines (if I’m right) :

Kirby::plugin('my/thumbs', [
    'components' => [
        'thumb' => function (App $kirby, string $src, string $dst, array $options) {
            $rootToThumb = myThumbGenerator($src, $dst, $options);

            return $rootToThumb;
        }
    ]
]);

Thx

You can find an example how to extend the im driver here: https://github.com/flokosiol/kirby-focus/blob/master/src/Focus/ImageMagick.php

Ok, this is my try with -solarize, but I don’t know if I’m in the right way

<img src="<?php echo $cover->thumb(['width' => 400, 'quality' => 100, 'solarize' => '0.2'])->url() ?>">

<?php
Kirby::plugin('my/thumbs', [
    'components' => [
        'thumb' => function (App $kirby, string $src, string $dst, array $options) {
            function solarize(string $file, array $options)
            {
                    return '-solarize' . $options['solarize'];
            }
        }
    ]
]);

because the solarize effect is not working yet

I don’t think it works like this. The thumbs component is intended to replace the original thumbs component, not to add methods to a given driver. Have you checked out the example?

Yep, so, thanks to this topic

I understand I have to use this

$file->thumb(['width' => 400, 'own' => true]) to use my own method.

with these lines inside the component :

<?php
Kirby::plugin('my/thumbs', [
    'components' => [
        'thumb' => function (Kirby\Cms\App $kirby, string $src, string $dst, array $options) {
            if (isset($options['own']) === true) {
                return myThumbGenerator($src, $dst, $options);
            }
            
            $core = require $kirby->root('kirby') . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'components.php';
            return $core ['thumb']($kirby, $src, $dst, $options);
        }
    ],
]);

But still don’t understand how to insert this function :

function oilPaintImage($imagePath, $radius)
{
    $imagick = new \Imagick(realpath($imagePath));
    $imagick->oilPaintImage($radius);
    header("Content-Type: image/jpg");
    echo $imagick->getImageBlob();
}

The thread you mention is about using your own thumbs component, not adding a function to a driver. That means, with the component you can exchange Kirby’s thumb component (not the driver) and replace it with your own, e.g. if you want to create your thumbs via a CDN etc.

In your case that means, that you copy the IM driver, make your changes and then include it like in the focus crop example.

Maybe it is possible to just use that function inside your own component that does nothing else than executing this function, have never tested this.

Thank you Sonja
I was able to change a command line from the kirby-focus-plugin to make a risographic effect with noise and grayscale. Maybe one day, let’s be crazy, I could edit a new plugin to make nice effects to images.

Bye !