Search code examples
javascriptnode.jscss-spritesgraphicsmagick

Stitching images with append() in graphicsmagick


I have a large number of images stored on a separate server that needs to be displayed on a single page as a mosaic of some sort where the individual elements may be shown or hidden dynamically.

These images should be fetched, resized and then stitched together as a sprite, and used as background images on divs. Fetching and resizing is a non-issue at this point, as the biggest hurdle is understanding the append method, or rather how to add images to a set, in order to use said method.

According to the docs:

gm("img.png").append(ltr)

should:

Append a set of images

How do I get multiple images into a "set"?


Solution

  • Best I could do, was as follows ...

    var gm = require('gm')
    
    gm('@images.txt')
      .append()
      .write('crazy.png', function (err) {
        if (!err) console.log('crazytown has arrived');
      })
    

    Where images.txt is a list of images to append.

    Have not yet been able to figure out how to pass a set of images other than an image list file.

    Got the idea from the website - http://www.graphicsmagick.org/GraphicsMagick.html

    When running a commandline utility, you can prepend an at sign @ to a filename to read a > list of image filenames from that file. This is convenient in the event you have too many > image filenames to fit on the command line.

    Hope that helps LeeT