graphicsmagick-stream
Fast convertion/scaling of images using a pool of long lived graphicsmagick processes
npm install graphicsmagick-stream
It works by spawning and reusing a custom graphicsmagick processes (see src/) that accepts images over stdin and pipes out the converted result over stdout
Usage
var gm = var fs = var convert = fs
You do not need to set all the options. If you only want to scale an image do
var stream =
You can also use it to get metadata info about an image using convert.info
var info = convertfs
For more examples and usage see the test folder
Scale types
contain
sets the scaled image to maximum have a width/height of the scale box. Always respects ratio.cover
sets the scaled image to at least have one of the width/height within the scale box. Always respects ratio.fixed
sets the scaled image to precisely the given width/height of the scale box. If both width/height is given it does not respect the ratio.
PDF Conversion
If you install ghostscript as well you will be able to convert pdfs to images by simply piping in a pdf and setting output format to jpeg
(or another image format).
If you are rendering a multipage pdf scale.height
will set the height of each page. To force scale.height
to donate the height of the entire image set scale.multipage = true
.
Use split = true
to output each page as an image file. This will result in a tar file containing all the images, so you will need to untar them on the other end. Use a project like tar-stream to achieve this.
Dependencies
You need to install libgraphicsmagicks in order to compile this.
Using OS X and Homebrew
brew install graphicsmagick --build-from-sourcebrew install libarchive
You will have to build the binary using the following command
gcc src/*.c -o bin/convert -L/usr/local/opt/libarchive/lib -I/usr/local/opt/libarchive/include -larchive -O `GraphicsMagickWand-config --cflags --cppflags --ldflags --libs`
Using Ubuntu
sudo apt-get install build-essential libgraphicsmagick++1-dev libarchive-dev
Then npm install
should work.
License
MIT