This article mainly introduces node-images, a middleware for processing images by nodejs, which is of great practical value, for more information about node-images, see the next article. It is very useful.
Cross-platform image decoder (png/jpeg/gif) and encoder (png/jpeg) for Node. js
Node. js lightweight cross-platform image codec Library
Var images = require ("images"); images ("input.jpg") // Load image from file // Load the image file. size (400) // Geometric scaling the image to 400 pixels width // proportional scaling the image to 400 pixels width. draw (images ("logo.png"), 10, 10) // Drawn logo at coordinates (10, 10) // draw a Logo at (10, 10. save ("output.jpg", {// Save the image to a file, whih quality 50 quality: 50 // save the image to the file, the image quality is 50 });
Features
Lightweight: no need to install any image processing library.
Lightweight: no image processing library is required.
Cross-platform: Released a compiled. node file on windows, just download and start.
Cross-platform: A compiled. node file is released in Windows, which can be downloaded.
Easy-to-use: Provide jQuery-like chaining API. Simple and reliable!
Easy to use: jQuery APIs are simple and reliable.
Install Installation
$ npm install images
API
Node-images provide jQuery-like Chaining API, You can start the chain like this:
Node-images provides a jQuery-like chained call API. You can start with this:
/* Load and decode image from file * // * Load and decode the image from the specified file */images (file) /* Create a new transparent image * // * Create a transparent image with the specified width and height */images (width, height) /* Load and decode image from a buffer * // * decodes the image from the Buffer data */images (buffer [, start [, end]) /* Copy from another image * // * Copy an image from another image to create an image */images (image [, x, y, width, height])
Images (file)
Load and decode image from file Load and decode the image from the specified file
Images (width, height)
Create a new transparent image Create a transparent image with a specified width and height
Images (buffer [, start [, end])
Load and decode image from a buffer decodes the image from the Buffer data
Images (image [, x, y, width, height])
Copy from another image Copy area from another image to Create image
. Fill (red, green, blue [, alpha])
Eg: images (200,100). fill (0xff, 0x00, 0x00, 0.5) Fill image with color to fill the image with the specified color
. Draw (image, x, y)
Draw image on the current image position (x, y) Draw an image on the current image (x, y)
. Encode (type [, config])
Eg: images ("input.png"). encode ("jpg", {operation: 50}) Encode image to buffer, config is image setting.
Encode the current image to the Buffer in the specified format, and set config as the image. Currently, JPG image quality can be set.
Return buffer
Return the filled Buffer.
Note: The operation will cut off the chain
Note: This operation will cut off the call chain.
See:. save (file [, type [, config]) Reference:. save (file [, type [, config])
. Save (file [, type [, config])
Eg: images ("input.png "). encode ("output.jpg", {operation: 50}) Encoding and save the current image to a file, if the type is not specified, type well be automatically determined according to the file, config is image setting. eg: {operation: 50}
Encode and save the current image to file. If the type is not specified, the file type is automatically determined based on the file. config is the image setting. Currently, JPG image quality can be set.
. Size ([width [, height])
Get size of the image or set the size of the image, if the height is not specified, then scaling based on the current width and height to Get or set the image width and height, if the height is not specified, the system scales according to the current width-to-height ratio.
. Resize (width [, height])
Set the size of the image, if the height is not specified, then scaling based on the current width and height
Sets the image width and height. If the height is not specified, the image scales based on the current width and height ratio. By default, The bicubic algorithm is used.
. Width ([width])
Get width for the image or set width of the image Get or set the image width
. Height ([height])
Get height for the image or set height of the image Get or set the image height
Images. setLimit (width, height)
Set the limit size of each image sets the size limit of the image to be processed by the library. the setting takes effect for all new operations (if the limit is exceeded, an exception is thrown)
Images. setGCThreshold (value)
Set the garbage collection threshold to Set the automatic gc threshold of the image processing database (when the new memory usage exceeds this threshold, garbage collection is executed)
Images. getUsedMemory ()
Get used memory (in bytes) to Get the memory size occupied by the image processing Library (in bytes)
Images. gc ()
Forced call garbage collection forcibly calls V8's garbage collection mechanism
Github.com/zhangyuanwei/node-images