0

How to fix Error: Stream yields empty buffer in Node.js v14.15.3?

Here is some code how I use ImageMagick to process images:

const gm = require('gm').subClass({ imageMagick: true });

const resize = (imageStream, width, height) =>
  new Promise((res, rej) => {
    gm(imageStream.on('error', rej))
      .resize(width, height, '>')
      .noProfile()
      .toBuffer('jpeg', (err, data) => (err ? rej(err) : res(data)));
  });

Error throws when image resolution higher than 4000x5000 pixels

ImageMagic Resource limits:
  Width: 64MP
  Height: 64MP
  List length: 18.446744EP
  Area: 3.2212GP
  Memory: 2GiB
  Map: 3GiB
  Disk: 10GiB
  File: 786432
  Thread: 2
  Throttle: 0
  Time: unlimited

Could someone help me with this?

  • I don't speak `node`, so could you explain 1) how you found those resource limits - I mean what command did you run? 2) I am unclear as regards what size image you start with (in pixels wide by pixels tall) and what size images you end up with. Thanks. – Mark Setchell Aug 09 '21 at 16:36
  • @MarkSetchell Here is command from official documentation: **identify -list resource** [link](http://www.imagemagick.org/script/command-line-options.php#limit) Input image size can be random(up to 20 000x15 000 pixels) Resize output should be 1080*1920 and 300*300 px – Максим Выхрист Aug 09 '21 at 17:20
  • Can you be sure that the same resource limits apply within `node` as at the command-line? I have often seen folks use two different installations/versions of **ImageMagick** with different resource limits and mistakenly believing they are using the other version - more so with PHP but nonetheless. – Mark Setchell Aug 09 '21 at 17:26

0 Answers0