nodejs提取gif中的图片

2021/6/9 11:36:41图片处理nodejs

一,安装graphicsmagick
Mac安装:https://github.com/aheckmann/gm#readme

brew install imagemagick
brew install graphicsmagick
// 如果要支持webp,需要安装下面的
brew install imagemagick --with-webp

Win安装:http://www.graphicsmagick.org/
下载后,配置环境变量,把安装目录设置为环境变量
验证是否安装成功:打开cmd
image.png
二,安装 nodejs版的gm(教程:http://aheckmann.github.io/gm/

yarn add gm

三,提取gif图片(提取第一帧)

index.mjs

import gm from 'gm'

gm('./image.gif[0]')
    .write('./image.png', function (err) {
        if (err) console.log(err);
    });

package.json

{
  "name": "temp-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "run": "node index.mjs"
  },
  "type": "module",
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "gm": "^1.23.1"
  }
}

注意:为了支持在index.mjs中使用import语法,必须在package.json中配置 "type": "module"

========================================
如果你觉得文章帮你解决了问题和疑惑,可以请作者喝杯咖啡
image.pngimage.png
支付宝扫码 微信扫码