1

I'm writing a script that takes an image and creates multiple variants of different sizes (like imgur, basically). Right now, I do the following for each variant using https://github.com/aheckmann/gm in node.js:

function(file, size, newfile, callback) {
  gm(file)
    .noProfile()
    .quality(80)
    .resize(size, size)
    .write(newfile, callback)
}
  1. I assume that each time I resize the image, graphicsmagick reads the image form the disk and loads it into memory. Is this correct? If so, how can I make read from disk only once?
  2. Can I read the file from a stream, then run multiple resizes on a single stream? I don't know enough about streams, and when I tried doing this last, I got frustrated, gave up, and deleted that portion of the code.
Jonathan Ong
  • 19,927
  • 17
  • 79
  • 118
  • nope. i just store it as a buffer for now: https://github.com/discore/image-resize-s3 – Jonathan Ong Jun 25 '13 at 07:14
  • just as an aside: doing this would kill your memory, so it's not advisable if you're on a low memory platform like heroku. you're betting off using mpc files: http://www.imagemagick.org/Usage/files/#mpc – Jonathan Ong Jul 22 '13 at 19:49

1 Answers1

2

Here are two commandline examples how to do it with ImageMagick.

They use the mpr: syntax supported by ImageMagick, which tells ImageMagick to temporarily save the input image into a named memory program register, from which it can later (while processing) read the data much faster than it could do from harddisk.

It should be easy for you to translate these commandlines into parlance.

Community
  • 1
  • 1
Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345