# Altering image server-sided

**URL:** <https://forum.getkirby.com/t/altering-image-server-sided/28243>\
**Category:** Questions\
**Created:** [March 30, 2023, 10:28pm UTC](https://forum.getkirby.com/t/altering-image-server-sided/28243 "2023-03-30T22:28:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kale](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kale/32/10525_2.png) [@Kale](https://forum.getkirby.com/u/Kale)\
**Post date:** [March 30, 2023, 10:28pm UTC](https://forum.getkirby.com/t/altering-image-server-sided/28243/1 "2023-03-30T22:28:38Z")

</div>

Hello,

I am currently looking for ways to change the contrast of images server-sided. I would like to use certain images as a mask. For cross-broswer-compatibility, I would like to use the images as css mask instead of svg filters and svg masks. This requires the images to already be b/w and high contrast. Is there a way to use e.g. ImageMagick or some other php library or kirby plugin within kirby to do so? I am thinking about something like $image-\>brightnessContrastImage($brightness, $contrast, $channel)-\>url()

Thank you for any hint!

---

<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:** [March 31, 2023, 5:46am UTC](https://forum.getkirby.com/t/altering-image-server-sided/28243/2 "2023-03-31T05:46:53Z")

</div>

You could create a custom thumb driver for ImageMagick with support for such image manipulations.

> **[Darkroom driver](https://getkirby.com/docs/reference/plugins/extensions/darkroom-drivers)**

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [March 31, 2023, 8:38am UTC](https://forum.getkirby.com/t/altering-image-server-sided/28243/3 "2023-03-31T08:38:37Z")

</div>

kirby uses simpleimage under the hood which has methods to darken or change contrast. but like said kirby does not expose all of the available methods (which i dont know why to be honest) so you need to create a custom wrapper (the darkroom) to call them there.

> **[GitHub - claviska/SimpleImage: A PHP class that makes working with images and...](https://github.com/claviska/SimpleImage#contrastpercentage)**
>
> A PHP class that makes working with images and GD as simple as possible. - GitHub - claviska/SimpleImage: A PHP class that makes working with images and GD as simple as possible.

---

<div class="post-metadata">

**Author:** ![Kale](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kale/32/10525_2.png) [@Kale](https://forum.getkirby.com/u/Kale)\
**Post date:** [March 31, 2023, 9:32am UTC](https://forum.getkirby.com/t/altering-image-server-sided/28243/4 "2023-03-31T09:32:00Z")

</div>

Thank you for the replies! I am quite new to this level of working with php so please exuse my possibily naive question.

I thought about altering the grayscale method to also increase the contrast of my image. I created a file `plugins/customGrayscale/index.php` with the following code:

```auto
<?php

class CustomImageMagick extends Kirby\Image\Darkroom\ImageMagick
{
	protected function grayscale(string $file, array $options): ?string
	{
		if ($options['grayscale'] === false) {
			return $image;
		}

		return $image->desaturate()->contrast(80);
	}

}

Kirby\Image\Darkroom::$types['custom-im'] = CustomImageMagick::class;

```

However, this does not change anything. It probably is not as easy, right? Do I have to register the plugin elsewhere? Do you maybe have a code example of a simple custom thumb driver, where I could see how it is done and how it is registered?

Thank you!

---

<div class="post-metadata">

**Author:** ![Kale](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kale/32/10525_2.png) [@Kale](https://forum.getkirby.com/u/Kale)\
**Post date:** [April 3, 2023, 11:27am UTC](https://forum.getkirby.com/t/altering-image-server-sided/28243/5 "2023-04-03T11:27:35Z")

</div>

Or could you maybe just point me to an example of a custom thumb driver? That would be of great help!

---

<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:** [April 3, 2023, 11:36am UTC](https://forum.getkirby.com/t/altering-image-server-sided/28243/6 "2023-04-03T11:36:13Z")

</div>

The focus plugin has a custom thumb driver: [Focus | Kirby CMS](https://getkirby.com/plugins/flokosiol/focus)

---

<div class="post-metadata">

**Author:** ![rasteiner](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/rasteiner/32/4788_2.png) [@rasteiner](https://forum.getkirby.com/u/rasteiner)\
**Post date:** [April 3, 2023, 11:42am UTC](https://forum.getkirby.com/t/altering-image-server-sided/28243/7 "2023-04-03T11:42:04Z")

</div>

Also remember to delete eventual thumbnails generated in the `/media` folder between tests, otherwise it won’t generate new images with the same filename.  
Also remember to actually set your driver in the `config.php`:

```auto
return [
    'thumbs' => [
        'driver' => 'custom-im'
    ]
];

```
