gm is an image processing plug-in based on node.js. It encapsulates the image processing tools GraphicsMagick (GM) and ImageMagick (IM) and can be called using spawn. The gm plug-in is not installed by default in node. You need to execute "npm install gm -S" to install it before it can be used.
The operating environment of this tutorial: Windows 7 system, nodejs version 16, DELL G3 computer.
What is gm
nodejs image processing tool plug-in-gm, which encapsulates GraphicsMagick (GM) and ImageMagick (IM), It is called using spawn.
GraphicsMagick (GM) or ImageMagick (IM) are two commonly used image processing tools with basically the same functions. GM is a branch of IM.
Usage of nodejs image processing tool gm
Pre-installation software
Install GraphicsMagick or ImageMagick
(The IM software supported by the gm plug-in is imagemagickv7.0.X.XX version. If the downloaded IM version is 7.1.x, the gm call will not succeed. The currently officially provided version is 7.1 .x), 7.0.x download address http://m.downcc.com/d/398765.
When installing, be sure to select the part of the picture frame when installing ImageMagick (the gm plug-in calls the convert command)
Install gm
npm install gm -S
Add watermark
Using gm is mainly used to add watermarks, because the image module that comes with nodejs can meet most needs, but it cannot be added. Watermark, so let’s use the gm method to add a watermark.
Load gm module
const gm = require('gm').subClass({imageMagick: true})
Specify the picture to add text
gm(./uploads/pic/test.jpg) //指定添加水印的图片 .stroke("white") //字体外围颜色 .fill("white") //字体内围颜色(不设置默认为黑色) .drawText(50,50,"China") .write(./uploads/pic/watermark.jpg, function (err) { console.log(err) if (!err) console.log('ok'); else console.log(err); });
Add Chinese font
.font("./ttf/msyh.ttf",60) //字库所在文件夹和字体大小
gm(./uploads/pic/test.jpg) //指定添加水印的图片 .stroke("white") //字体外围颜色 .fill("white") //字体内围颜色(不设置默认为黑色) .font("./ttf/msyh.ttf",60) //字库所在文件夹和字体大小 .drawText(50,50,"中文China") .write(./uploads/pic/watermark.jpg, function (err) { console.log(err) if (!err) console.log('ok'); else console.log(err); });
- ##Add date Watermark
npm install momentLoad module
const moment = require('moment');Calling
var datetime = moment().format("YYYY-MM-DD HH:mm:ss"); gm(./uploads/pic/test.jpg) //指定添加水印的图片 .stroke("white") //字体外围颜色 .fill("white") //字体内围颜色(不设置默认为黑色) .font("./ttf/msyh.ttf",60) //字库所在文件夹和字体大小 .drawText(50,50,datetime) .write(./uploads/pic/watermark.jpg, function (err) { console.log(err) if (!err) console.log('ok'); else console.log(err); });
nodejs tutorial!
The above is the detailed content of What is node.js gm. For more information, please follow other related articles on the PHP Chinese website!

Vercel是什么?本篇文章带大家了解一下Vercel,并介绍一下在Vercel中部署 Node 服务的方法,希望对大家有所帮助!

gm是基于node.js的图片处理插件,它封装了图片处理工具GraphicsMagick(GM)和ImageMagick(IM),可使用spawn的方式调用。gm插件不是node默认安装的,需执行“npm install gm -S”进行安装才可使用。

大家都知道 Node.js 是单线程的,却不知它也提供了多进(线)程模块来加速处理一些特殊任务,本文便带领大家了解下 Node.js 的多进(线)程,希望对大家有所帮助!

今天跟大家介绍一个最新开源的 javaScript 运行时:Bun.js。比 Node.js 快三倍,新 JavaScript 运行时 Bun 火了!

node怎么爬取数据?下面本篇文章给大家分享一个node爬虫实例,聊聊利用node抓取小说章节的方法,希望对大家有所帮助!

在nodejs中,lts是长期支持的意思,是“Long Time Support”的缩写;Node有奇数版本和偶数版本两条发布流程线,当一个奇数版本发布后,最近的一个偶数版本会立即进入LTS维护计划,一直持续18个月,在之后会有12个月的延长维护期,lts期间可以支持“bug fix”变更。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!
