A simple web interface to generate image.
A simple web interface to generate image using Sharp for Node.js.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
First clone the project to your development enviroment.
git clone https://github.com/domus71/imagesharp.git
You have to install Sharp ang Express framework usign npm.
npm install
The default port is 3001. You can change port from config.json
node index.js
On your browser to get information (metadata) as json object:
http://localhost:3001/getinfo?source=<fullpath of source image file>
On your browser to generate new image:
http://localhost:3001/generate?source=<fullpath of source image file>&dest=<fullpath of generated image file>&width=<pixels>&height=<pixels>&quality=<from 1 to 100>&lossless=<0/1/true/on>&progressive=<0/1/true/on>&wimage=<watermark file>&wposition=<watermark position ex.southwest>&pos=<image position for cropping, see rposition array>
The source and the destanation image paths must be url encoded. If width and height are 0, then image keeps the original size. The properties quality, lossless and progressive are optional. Default quality is 80%. Also, I have disabled the Sharp cache to get new file everytime. You can comment the line 9 to speed up things and change Sharp caching options. The generated image is centered and cropped/clipped in given dimensions to fit by default. You can change that using image position pos=0..8 (see rposition array 0:"left top", 1:"top" 2:"right top", ... 7: "bottom", 8: "right bottom")
You can change the port and/or convert it to Windows service using NSSM. I use it as an internal service to convert big PNG files to WebP format.
- Express - Server Framework
- Sharp - High performance Node.js image processing
- NodeJs - Server Environment
- Hate old Windows DLLs