question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

overlayWith raw input: memory area too small

See original GitHub issue

Hello,

node version: v7.4.0 ImageMagick version 6.9.6-8 Q16 x86_64 2016-12-12

I am doing images compositions and sometime I am getting this error: Error: VipsImage: memory area too small Error: VipsImage: memory area too small — should be 8000000 bytes, you passed 5262436

According to what I read on issues this is related to the raw option object given to sharp for overlayWith.

What am I doing?

base {
  "name": "38db6773-da81-402f-b457-b609e8966147-border.png",
  "path": "/tmp/38db6773-da81-402f-b457-b609e8966147-border.png",
  "dimensions": {
    "width": 2048,
    "height": 3591,
    "type": "png"
  },
  "options": {
    "raw": {
      "channels": 4,
      "width": 2048,
      "height": 3591
    }
  },
  "gravity": {
    "gravity": 0
  }
}
other ressource [
  {
    "name": "66b9f2dd-1b6b-48e1-b7b6-8b010b37ef97-qr.png",
    "path": "/tmp/66b9f2dd-1b6b-48e1-b7b6-8b010b37ef97-qr.png",
    "dimensions": {
      "width": 1147,
      "height": 1147,
      "type": "png"
    },
    "options": {
      "raw": {
        "channels": 4,
        "width": 1147,
        "height": 1147
      }
    },
    "gravity": {
      "gravity": 0
    }
  },
  {
    "name": "e29eca8c-01e2-4302-9b33-c59478826cf9-label.png",
    "path": "/tmp/e29eca8c-01e2-4302-9b33-c59478826cf9-label.png",
    "dimensions": {
      "width": 2000,
      "height": 1000,
      "type": "png"
    },
    "options": {
      "raw": {
        "channels": 4,
        "width": 2000,
        "height": 1000
      }
    },
    "gravity": {
      "gravity": 3
    }
  }
]

Base is the first ressource (the bigger one), and other ressources are the ressource I want to merge into it.

My composition:

   const composite = filesShifted.reduce((image: any, overlay: any) => {
    return image.then((raw: any) => {
     return sharp(raw, overlay.options).overlayWith(overlay.path, overlay.gravity).raw().toBuffer()
    })
   }, base)

I already had this error in another case and I managed to sort it out, while giving the bigger raw overlay.options for all of my ressource (meaning I was using only the overlay.options from the base for all ressources). However I supposed this is not the right way, and I supposed I had the chance that the allocated memory was enough for all of my ressources, but actually the raw options was innapropriate.

The right thing would be to iterate over my ressource and give the associated options. Actually this is what I am trying to do, but it does not work there. I get the vips error. Do you have an idea about how I can fix this?

Thanks in advance

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
lovellcommented, Mar 20, 2017

If you’re calling overlayWith multiple as part of a reduction, the dimensions passed to the constructor need to always be those of the base image.

The output dimensions of a base image overlaid with a second image will be the same as the base image.

-     return sharp(raw, overlay.options).overlayWith(overlay.path, overlay.gravity).raw().toBuffer()
+     return sharp(raw, base.options).overlayWith(overlay.path, overlay.gravity).raw().toBuffer()
0reactions
iiAkucommented, Mar 21, 2017

Ok got it ! Thanks you so much for your help and Sharp. 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Persistent Overlays — Singularity container 3.5 documentation
A persistent overlay is a directory or file system image that “sits on top” of your immutable SIF container. When you install new...
Read more >
sharp - High performance Node.js image processing
Only small regions of uncompressed image data are held in memory and processed at a time, taking full advantage of multiple CPU cores...
Read more >
Solved: Re: IMX8 Video overlay with graphics before H264 e ...
We need to overlay graphics onto the video stream prior to H264 encode as well as to the display on a low power...
Read more >
NucleoView™ NC-200™ Software User's Guide - ChemoMetec
Creating new cm-files with hidden protocols is NOT possible, but they can still run on already existing cm-files when run via Show Raw...
Read more >
Keyboard Control - mpv.io
mpv is a media player based on MPlayer and mplayer2. ... auto-copy selects only modes that copy the video data back to system...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found