1

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

halfer
  • 19,824
  • 17
  • 99
  • 186
  • 1
    Which line is giving the error, is it the `const gm` line? For reference, here is a tutorial that uses ImageMagick: [Tutorial: Using AWS Lambda with Amazon S3 - AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html) – John Rotenstein Jan 01 '19 at 22:09
  • using exactly the same. It is working on local ubuntu machine. But on lambda it is unable to find the binaries and give above issue. At first it gave the same issue on local and I ran `sudo install imagemagick` and it was fixed. – Osama Goraya Jan 01 '19 at 22:12
  • Is [this](https://stackoverflow.com/questions/44729088/how-can-i-install-graphicsmagick-or-imagemagick-on-aws-lambda) question able to help you? – Maurice Jan 01 '19 at 23:41
  • yes already tried that but its too complicated for me. I don't know that where to run the commands as lambda is serverless and where to find serverless.yml file. – Osama Goraya Jan 02 '19 at 08:46
  • Hi Osama. Please liaise with editors before performing a summary roll-back. I have downvoted as this is not acceptable behaviour for a new user on Stack Overflow. I will restore my version shortly, as begging is not an appropriate way of addressing volunteers. – halfer Jan 02 '19 at 08:49
  • @halfer I honestly don't know what going on with the editor right now. I get a notification and I just edit it. – Osama Goraya Jan 02 '19 at 08:52
  • Hmm, OK. Don't use the "rollback" feature unless you know what it does `:-)`. – halfer Jan 02 '19 at 08:54

0 Answers0