DEV Community

loading...

Image processing with Jimp. Optional methods parameters.

Kuba
・1 min read

Hi guys.

I'm working on some kind of cloud image hosting and processing. I do use Jimp, which is great and works like a charm.

Jimp's giving a lot of cool image processing methods, such as resizing, scaling and so on. You can chain methods to apply multiple effects, f.ex.:

Jimp.read('image/path')
 .then(image => {
     image
        .resize()
        .scale()
        .grayscale()
 })
 ....

What do I want to achieve

I want to process images in a fly. For example, I do have an URL:

[...].images.io/i/image-uuid?list=a&of=b&params=c

These params can be f.ex. width, height, scale, rotate etc.

For now I can manipulate image by giving one specific parameter f.ex.

[...].images.io/i/image-uuid?scale=0.5

and it's works - it's scaling image.

But I want to have opportunity to use bunch of options in one request f.ex.:
[...].images.io/i/image-uuid?scale=0.5&filter=grayscale&rotate=80

and I do not know how make it work. For now - Jimp offers more than 30 methods what gives us bunch of combinations so simple switch-case won't work. ;)

Basing on documentation, there is no thing such as optional params, and you cannot pass nulls or undefined as a method params.

Any ideas how can i overcome this? :)

Happy Holidays everyone!

Discussion (0)