How to fix Unhandled rejection Error: Could not execute GraphicsMagick/ImageMagick in AWS LAMBDA (NodeJS)

北城以北 提交于 2020-01-25 08:07:51

问题


Unhandled rejection Error: Could not execute GraphicsMagick/ImageMagick: gm "identify" "-ping" "-format" "%p" "/tmp/temp.pdf" this most likely means the gm/convert binaries can't be found

I have tried everything mentioned in similar questions. This is my first lambda function and I am stuck. Please find below how I am adding gm into my lambda function index.js

// dependencies
var AWS = require('aws-sdk');
var simpleParser = require('mailparser').simpleParser;
const gm = require('gm').subclass({ imageMagick : true});
var fs = require("fs");
let PDF2Pic = require('pdf2pic').default

let converter = new PDF2Pic({
 density: 100,           // output pixels per inch
 savename: "/tmp/temp",    // output file location
 format: "jpg"               // output size in pixels
});

// by default the first page of the pdf will be converted
// to image
 converter.convert("/tmp/temp.pdf")
   .then(resolve => {
       console.log("image converted successfully")
var contents = fs.readFileSync('/tmp/temp.jpg', 'utf8');
       console.log(contents);
   });

Executing this gives error :

converter.convert

来源:https://stackoverflow.com/questions/53999053/how-to-fix-unhandled-rejection-error-could-not-execute-graphicsmagick-imagemagi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!