What to do if node gm reports an error

藏色散人
Release: 2023-01-28 16:22:56
Original
2356 people have browsed it

Node gm error solution: 1. Install "ImageMagick 6.x"; 2. Add the ImageMagick installation directory to the environment directory Path, and modify the code to "require('gm').subClass({ imageMagick: true});" That's it.

What to do if node gm reports an error

The operating environment of this tutorial: linux5.9.8 system, node-v16.18.0 version, DELL G3 computer

node gm error what to do?

A collection of various problem solutions about nodejs gm (Chinese garbled characters, non-conforming drawing, ������)

1. Chinese garbled characters

graphicsmagick does not support Chinese font drawing (undetermined)

The most direct and effective method at present is to replace ImageMagick (both functions Exactly the same, no need to worry)

First install ImageMagick 6.x

(For 7.x, please check the "Install legacy utilities (e.g. convert)" option during installation)

What to do if node gm reports an error

Then, add the ImageMagick installation directory to the environment directory Path.

And make the following changes to your code:

const gm = require('gm')//原代码 const gm = require('gm').subClass({imageMagick: true});//修改后的代码
Copy after login

Next, check whether you have set theChinese font, and whether theencoding has been switched to Unicode.

For Chinese fonts, I recommend using Google's "Google Noto", which is supported in basically any language.

Example:

const gm = require('gm').subClass({imageMagick: true}); var text = "你好!ImageMagick!"; var img = gm(800, 2000, "#ffffffff");//创建一个800x2000的图片 img.font("./Noto.ttf",36);//设置字体,字体大小 img.encoding('Unicode');//设置编码为Unicode img.drawText(0, 50, "'" + text + "'");//此处 "'" 不能删除,删除会导致出现问题2(坑爹) img.write("test.png", function (err) {if(err)console.error(err)});//写出图片
Copy after login

2. An error message appears: Error: Command failed: convert: non-conforming drawing primitive definition

The text given to drawText Just add a ' on the left and right to solve it (functions with text can be solved this way)

Example:

img.drawText(0, 50, text);//错误 img.drawText(0, 50, "'" + text + "'");//正确方法
Copy after login

3. Error: Error: Command failed: ���� ��

usually appears in ImageMagick7.x and after setting imageMagick: true.

Reinstall 7.x and check the "Install legacy utilities (e.g. convert)" option during installation.

It took me a day to complete this gm....

Recommended study: "node.js video tutorial"

The above is the detailed content of What to do if node gm reports an error. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!