Automation Techs For Productivity And Fun

Bulk Resize Image Files Using OpenCV And Node.js

Installing OpenCV requires lot of work and disk space, so I know I should use other libraries like gm with GraphicsMagick or Jimp when I want to resize images with Node.js. Though I've already have OpenCV and opencv4nodejs installed, so I'll just write about resizing images using OpenCV.

"opencv4nodejs" is a wrapper package of OpenCV for Node.js. By using this package, you can call image processing functions included in OpenCV.

There are two functions for image resizing: "resize" and "resizeToMax". "resize" is for resizing or scaling image to specified size, and "resizeToMax" is for resizing image to height and width that fits specified max length keeping aspect ratio.

This time I wanted a script to bulk resize images in directory to fit in same size, so I used "resizeToMax".

Here's the script:

It resizes all jpeg images in SOURCE_DIRECTORY_PATH to fit 100 x 100 and saves it to DEST_DIRECTORY_PATH with same file name.


Search This Blog


Generate Data For Testing With PostgreSQL

When developing a software using PostgreSQL database as storage, the function "generated_series" is very useful to create data ...

Powered by Blogger.


Recent Posts