We often encounter the server upload images to crop or add logo and so on, how to do on the node platform?
See everyone in the use of "GM" this tool, the function is very powerful, but on the Windows platform is a variety of pits Ah, I have a whole afternoon, although some problems solved, but also chose another good, and lightweight cross-platform better module--images
Installation mode NPM Install images
GitHub address is Https://github.com/zhangyuanwei/node-images
As the author describes, lightweight, cross-platform, jquery-style
I'll just list a few of the features we've used to demo
1. Set or get the size of the picture
The first type:
1 var images = require ("Images"); 2 images ("image/test.jpg")3 . Size ()4 . Save ("Image/dist.jpg ");
The second Kind
1 var images = require ("Images"); 2 images ("image/test.jpg")3 . Width ()4 . Save ("image/ Dist.jpg ");
In either of these ways, if the parameter is not included, the width or height of the picture is returned, and the size returns a json,{width:,height:}, if the parameter is included, The picture will change the image size according to the parameter settings (there is also a resize () interface can also set the size of the picture)
2. Draw a region, currently images in this area function is relatively limited, can only draw square.
1 var images = require ("Images"); 2 images (400,400)3 . Fill (255,0,0,0.5)4 . Save ("image/ Dist.jpg ");
The above code draws a 400*400 Red square.
3. Draw the logo into the picture, this is still more practical, directly on the code
1 var images = require ("Images"); 2 images ("image/test.jpg")3 . Draw (Images ("image/logo.jpg"), 200,200) 4 . Save ("image/dist.jpg");
4. Capturing part of the image, this function and its usefulness, especially when capturing the user's avatar, is very meaningful
1 var images = require ("Images"); 2 images (Images ("image/test.jpg"), 200,200,500,500)3 . Resize (+4) . Save ("image/dist.jpg");
This is a few of the more common features of this tool, although a lot less than GM, but enough to meet most of our basic needs.
Node screenshot tool images (node-images)