munenendereba / node-batch-image-cropper

Using sharp library to batch-crop images with the same dimensions.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Batch Image Cropper on Node.js with sharp package

This is a simple project to enable you crop multiple images in a folder which have the same dimensions.

Description

Crop all those screenshots which to remove some portions such as identifiable info on your computer screen before sharing publicly. This uses the sharp package. This is part of my learning Node and I wanted to experiment.

Getting Started

Dependencies

  • You need Node installed in your environment
  • npm packages required: express, sharp, morgan-body and nodemon (for dev auto-restart)

Installing

  • Clone the repo or download from this repo.
  • Copy to a directory in your computer.

Installing as a Windows Service

Thanks to the great package node-windows, we can run this as a Windows Service that is installed on services.msc and can behave like a normal windows service.

Run the command node install.js to install and node uninstall.js to uninstall the service. It will appear as below once installed.

Batch Image Cropper Windows Service

Follow the Github link for more info about node-windows.

Executing program

  • Install all the dependencies as shown above by running commands below
npm init -y

If any dependency is not installed, you can install as below:

- npm install express sharp morgan-body
- npm install --save-dev nodemon

Start the application using the normal npm commands:

npm start

On the browser, navigate to http://localhost:3031/ and input the parameters as shown below and click "Start cropping..." button.

Image Parameters

On your browser window, you will get the below output:

Cropping Complete

On the console, you will get the below output:

Processing images

Improvements

The project needs to improve in the following:

  • Connect to a front-end (React) for input of the parameters such as path, image cropping dimensions etc. DONE
  • Better error handling
  • Organize the project better with folders etc.
  • Additional functionality:
    • Start and stop the application processing
    • Choose the path. Directory picker browser support is scanty for now. Implement later.
    • Choose whether to delete the original files etc.

Help

If you get errors when processing, check the following:

  • The image path exists
  • The dimensions are correct. I used MS Paint to determine the start and the dimensions of the cropped image.

Authors

Munene Isaka

Version History

  • 1.0.0

  • 1.1.0

    • Added front-end features
  • 1.2.0

    • Added Windows Service Feature

License

This project is licensed under the MIT License.

Acknowledgments

Inspiration, code snippets, etc.

About

Using sharp library to batch-crop images with the same dimensions.


Languages

Language:JavaScript 57.6%Language:EJS 34.2%Language:CSS 8.2%