Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
GraphicsMagick for node
JavaScript Makefile

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
lib
.gitignore
History.md
README.md
index.js
package.json

README.md

gm

GraphicsMagick for node

var gm = require('./gm')

// resize and remove EXIF profile data
gm('/path/to/my/img.jpg')
  .resize(240, 240)
  .noProfile()
  .write('/path/to/resize.png', function(err){
    if (!err) print('done')
})

// obtain the size of an image
gm('/path/to/my/img.jpg')
  .size(function(err, size){
    if (!err)
      print( size.width > size.height ? 'wider' : 'taller than you' )
  })

// output all available image properties
gm('/path/to/img.png')
  .identify(function(err, data){
    if (!err) console.dir(data)
  })

// pull out the first frame of an animated gif and save as png
gm('/path/to/animated.gif[0]')
  .write('/path/to/firstframe.png', function(err){
    if (err) print('aaw, shucks')
  })

// crazytown
gm('/path/to/my/img.jpg')
  .flip() 
  .magnify()
  .rotate('green', 45)
  .blur(7, 3)
  .crop(300, 300, 150, 130)
  .edge(3)
  .write('/path/to/crazy.jpg', function(err){
    if (!err) print('crazytown has arrived')
  }) 

// annotate an image
gm('/path/to/my/img.jpg')
  .stroke("#ffffff")
  .drawCircle(10, 10, 20, 10)
  .font("Helvetica.ttf", 12)
  .drawText(30, 20, "GMagick!")
  .write("/path/to/drawing.png", function(err){
    if (!err) print('done')
  })

// creating an image
gm(200, 400, "#ddff99f3")
  .drawText(10, 50, "from scratch")
  .write("/path/to/brandNewImg.jpg", function(err){
    // ...
  })

Getting started

First download and install GraphicsMagick

then either use npm: npm install gm

or clone the repo: git clone git://github.com/aheckmann/gm.git

Examples:

Check out the examples directory to play around. Also take a look at the Extending gm page to see how to customize gm to your own needs.

Constructor:

There are a few ways you can use the gm image constructor.

  • 1) gm(path) When you pass a string as the first argument it is interpreted as the path to an image you intend to manipulate.
  • 2) gm(width, height) When you pass two arguments it tells gm to create a new image on the fly with the provided dimensions. And you can still chain just like you do with pre-existing images too. See here for an example.
  • 3) gm(width, height, color) The same as #2 but you may also specify a background color for the created image.

Methods

Node version

Compatible with v0.1.96+g

Inspiration

http://github.com/quiiver/magickal-node

License

(The MIT License)

Copyright (c) 2010 Aaron Heckmann

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Something went wrong with that request. Please try again.