How to set the image middleware instance in nodejs

Source: Internet
Author: User
Tags image processing library transparent image
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

  1. Lightweight: no need to install any image processing library.

  2. Lightweight: no image processing library is required.

  3. Cross-platform: Released a compiled. node file on windows, just download and start.

  4. Cross-platform: A compiled. node file is released in Windows, which can be downloaded.

  5. Easy-to-use: Provide jQuery-like chaining API. Simple and reliable!

  6. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.