# ImageMagick thumbs additional function

**URL:** <https://forum.getkirby.com/t/imagemagick-thumbs-additional-function/19217>\
**Category:** Questions\
**Tags:** v3\
**Created:** [August 31, 2020, 6:06pm UTC](https://forum.getkirby.com/t/imagemagick-thumbs-additional-function/19217 "2020-08-31T18:06:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oziris](https://avatars.discourse-cdn.com/v4/letter/o/df788c/32.png) [@Oziris](https://forum.getkirby.com/u/Oziris)\
**Post date:** [August 31, 2020, 6:06pm UTC](https://forum.getkirby.com/t/imagemagick-thumbs-additional-function/19217/1 "2020-08-31T18:06:04Z")

</div>

Hi  
I would like to use an [ImageMagick function](https://phpimagick.com/Imagick/oilPaintImage), 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) :

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

            return $rootToThumb;
        }
    ]
]);

```

Thx

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [August 31, 2020, 6:17pm UTC](https://forum.getkirby.com/t/imagemagick-thumbs-additional-function/19217/2 "2020-08-31T18:17:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Oziris](https://avatars.discourse-cdn.com/v4/letter/o/df788c/32.png) [@Oziris](https://forum.getkirby.com/u/Oziris)\
**Post date:** [August 31, 2020, 7:27pm UTC](https://forum.getkirby.com/t/imagemagick-thumbs-additional-function/19217/3 "2020-08-31T19:27:42Z")

</div>

Ok, this is my try with [-solarize](https://imagemagick.org/script/command-line-options.php#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

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [August 31, 2020, 7:50pm UTC](https://forum.getkirby.com/t/imagemagick-thumbs-additional-function/19217/4 "2020-08-31T19:50:35Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Oziris](https://avatars.discourse-cdn.com/v4/letter/o/df788c/32.png) [@Oziris](https://forum.getkirby.com/u/Oziris)\
**Post date:** [August 31, 2020, 9:18pm UTC](https://forum.getkirby.com/t/imagemagick-thumbs-additional-function/19217/5 "2020-08-31T21:18:00Z")

</div>

Yep, so, thanks to this topic

> [@Extend core component thumb](https://forum.getkirby.com/t/extend-core-component-thumb/13633/14):
>
> Kirby::plugin('moeli/own-thumb', ['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); } ], ]); Thx @di…

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 :

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

```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [September 1, 2020, 7:11am UTC](https://forum.getkirby.com/t/imagemagick-thumbs-additional-function/19217/6 "2020-09-01T07:11:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Oziris](https://avatars.discourse-cdn.com/v4/letter/o/df788c/32.png) [@Oziris](https://forum.getkirby.com/u/Oziris)\
**Post date:** [September 1, 2020, 10:26am UTC](https://forum.getkirby.com/t/imagemagick-thumbs-additional-function/19217/7 "2020-09-01T10:26:15Z")

</div>

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 !
