gm icon indicating copy to clipboard operation
gm copied to clipboard

ImageMagick / Caption / Two files

Open stockholmux opened this issue 10 years ago • 3 comments

I'm trying to use the caption command from ImageMagick as I need the word wrap.

Here is what I'm trying now:

var
  gm = require('gm'),
  im = gm.subClass({ imageMagick: true });

im(200, 400, "#666666")
  .font("OpenSans-Light.ttf", 12)
  .stroke("#ffffff")
  .drawCircle(10, 10, 20, 10)
  .drawText(50,50,'drawn text')
  .out("caption: \"ImageMagick Text\"")
  .write("./brandNewImg.png", function (err) {
    console.log('error',err);
    console.log('done');
  });

The script is producing two files brandNewImg-0.png and brandNewImg-1.png. The 0 file has all the comands up to the drawText and the 1 file contains only the ImageMagick Text output (none of the other graphic elements and oddly on a white background). What's going on here?

stockholmux avatar May 14 '14 16:05 stockholmux

Oh boy. Half a day lost on this.

im(200, 400)
  .background("#666666")
  .font("OpenSans-Light.ttf", 12)
  .stroke("#ffffff")
  .drawCircle(10, 10, 20, 10)
  .drawText(50,50,'drawn text')
  .out("caption: \"ImageMagick Text\"")
  .write("./brandNewImg.png", function (err) {
    console.log('error',err);
    console.log('done');
  });

It appears that indicating the background color when initially calling was throwing a spanner in the works - I saw that placing the background color in the initial call was putting xc:#666666 on the command line which IM didn't like. Still a very unexpected problem/bug.

stockholmux avatar May 14 '14 19:05 stockholmux

Just wanted to add that I ran into the exact same problem where 2 image files were created instead of just 1. Also, it seems like the .out() function is undocumented.

danieltian avatar Jul 16 '18 12:07 danieltian

I ran into the same problem and what worked for me was adding .out('-composite') right after .out('-caption: "text to be wrapped"'). From what I understood the composite commande merges the 2 images.

aliamrani avatar Feb 14 '20 12:02 aliamrani