DEV Community

Kuba
Kuba

Posted on

2 1

Image processing with Jimp. Optional methods parameters.

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!

Image of Datadog

Master Mobile Monitoring for iOS Apps

Monitor your app’s health with real-time insights into crash-free rates, start times, and more. Optimize performance and prevent user churn by addressing critical issues like app hangs, and ANRs. Learn how to keep your iOS app running smoothly across all devices by downloading this eBook.

Get The eBook

Top comments (0)

Postgres on Neon - Get the Free Plan

No credit card required. The database you love, on a serverless platform designed to help you build faster.

Get Postgres on Neon