aheckmann / gm

GraphicsMagick for node
http://aheckmann.github.com/gm/
6.95k stars 615 forks source link

Any way to composite a current GraphicsMagick object onto another image? #851

Open rjindael opened 1 year ago

rjindael commented 1 year ago

Hi, I was wondering if there's a way to compose the current GraphicsMagick object onto another image. Currently, the way I do it is like so:

const fs = require("fs")
const gm = require("gm")

let overlay = gm(1280, 720, "#FFFFFF")

// ... add text to image, etc ...

// now to put *this* image on top of *another* image
// currently I write this image to a temporary file, and then call composite

overlay.write("image_overlay.png")
let underlay = gm("underlay_template.png")
underlay.composite("image_overlay.png")
underlay.write("image.png")
fs.rmSync("image_overlay.png")

The reason the underlay has to be separate from the underlay template image is due to the fact that I need to call functions such as raise and such on the overlaying image (i.e. specific effects to the overlay layer.) I'm not sure if I'm missing anything, but please correct me if I am.

Thanks!