Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the gm module of Node.js to process pictures

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

In this article Xiaobian introduces in detail for you "how to use Node.js 's gm module to deal with pictures", the content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to use Node.js 's gm module to deal with pictures" can help you solve your doubts.

Description of structural parameters

Encoding sets the received data encoding. Default is utf-8.

MaxFieldsSize limits the amount of memory that can be allocated to fields. The default is 2m.

MaxFields limits the number of fields that will be parsed before issuing an error event. The default is 1000.

MaxFilesSize limits the total file size. The default is infinite.

AutoFields enables field events and disables some of the field events. If you add a field listener, it is automatically set to true.

AutoFiles enables file events and disables some of the file events. If a file listener is added, it is automatically set to true.

The directory where the uploadDir file is uploaded

= = if the callback is provided, autofields and autofiles are set to true, and all fields and files are collected and passed to the callback, eliminating the need to listen to events of any kind. = =

Event description

Triggered when part requests file data, and the callback function is an instance object that implements a readable stream

Headers: header file

Name: field name

Filename: file name

ByteFffset: byte offset of principal data

ByteCount: the total byte length of the data

Aborted triggers when a request is aborted

Close is triggered after the request is completed

File received the parameters of the file

Name: field name

File: the object that stores file information

FieldName: field name

OriginalFilename: file name

Path: the specific path to write to the file on disk

Headers: stores header information

Size: specific file size

Field gets the specific data of the request. Two parameters of the callback function

Name: field name

Value: field valu

= = Note that when using the part event, if both fields and files events are monitored, the part event will not get the data. = =

More explanation

Generally speaking, uploading pictures will be processed simply, such as lossless image quality compression, thumbnail generation, etc.

1. Use resize-img to make thumbnails.

Install component

Npm install-save resize-img

Code implementation

2. Use python image processing library PIL

Why use python?

CPU-intensive tasks are the weakness of Node.js. When the server performs multiple image processing at the same time (especially for larger images), BUG will appear, so we can choose python image processing library PIL.

PIL installation

Python implementation

Node calls pyhton

Here I recommend the second method.

After reading this, the article "how to use Node.js 's gm module to deal with pictures" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it to understand it. If you want to know more about related articles, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report