1

AWS lambda Imagemagick convert failed for images of larger file dimension to jp2(jp2000). For images of size less then 60MB, conversion works fine, but above 60MB, I am getting 0KB file. I am using Imagemagick with child_process spawning for image conversion.

Using AWS lambda with Node.js 6.1, 1.5GB memory and 300 second timeout

I am not able to identify why the following code is failing for larger dimension images. Is this a buffer limitation of the child_process?

 var fs = require('fs'); var childproc= require('child_process'); var child = childproc.spawn('convert', [inputfile,outputFile,]); var file = fs.createWriteStream(tempDest, {encoding: 'binary'}); child.stdout.pipe(file); child.on('exit', function(){ file.end();console.log("file outputed");wcallback(null);}); child.on('error', function(err){ file.end();console.log(err);wcallback(err);}); 


I tried Imagemgick node.js wrapper package "npm Imagemagick", also. It was giving an error for the same conversion for larger file. The following is the error:

{ "errorMessage" : "Command failed: ", "errorType" : "Error", "stackTrace" : ["ChildProcess.<anonymous> (/var/task/node_modules/imagemagick/imagemagick.js:92:15)", "emitTwo (events.js:106:13)", "ChildProcess.emit (events.js:191:7)", "maybeClose (internal/child_process.js:886:16)", "Socket.<anonymous> (internal/child_process.js:342:11)", "emitOne (events.js:96:13)", "Socket.emit (events.js:188:7)", "Pipe._handle.close [as _onclose] (net.js:497:12)"]} 
7
  • 2
    A 60MB JPEG is enormous - what are its dimensions in pixels? Commented Oct 9, 2017 at 18:54
  • @MarkSetchell We are having TIFF images mostly and dimension are of 9000X9000. One image details Eg: Image.114614.tif=>Image.114614.jp2 TIFF 7800x8731 7800x8731+0+0 8-bit TrueColor sRGB 78.3729MiB 113.803u 3:19.139 Commented Oct 9, 2017 at 19:30
  • 9000x9000 pixels means around 500MB of RAM in Q16 ImageMagick when decompressed before you start copying or editing... 9000x9000=81Mpixels, with 2 bytes each of Red, Green and Blue, i.e. 81*6 = 486MB or 650MB with transparency. Commented Oct 9, 2017 at 19:33
  • In fact, creating a simple 9000x9000 JPEG on my machine takes 1.2GB of RAM... /usr/bin/time -l convert -size 9000x9000 xc:gray test.jpg Commented Oct 9, 2017 at 19:39
  • Is there any way for limiting/controling the memory usage while convertion. I have limitation like 1.5GB max memory and 5 minute max time allowable for execution in AWS lambda, so conversion should complete before 5 minutes. Commented Oct 9, 2017 at 19:54

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.