gm("img.png").adjoin()
gm("img.png").affine(matrix)
By default all imgs are anti-aliased by GraphicsMagick. To disable it pass false.
gm("img.png").antialias(false)
Append a set of images
img
ltr
(optional)Boolean
- specifies append directiontrue
for left-to-rightfalse
for top-to-bottom (default)gm("img.png").append(img [, img, ltr])
// appends another.jpg to img.png from left-to-right
gm("img.png").append("another.jpg").append(true)
// appends another.jpg to img.png from left-to-right
gm("img.png").append("another.jpg", true)
// appends another.jpg to img.png from top-to-bottom
gm("img.png").append("another.jpg")
// appends third.gif below another.jpg below img.png
gm("img.png").append("another.jpg").append("third.gif")
// appends third.gif below another.jpg below img.png
gm("img.png").append("another.jpg", "third.gif")
// appends third.gif to the right of another.jpg to the right to img.png
gm("img.png").append("another.jpg", "third.gif", true)
gm("img.png").authenticate(password)
Auto-orients the image according to its EXIF data.
GraphicsMagick doesn't actually have the -auto-orient option but we emulate this by first reading the EXIF data and rotate/flip from there.
gm("img.jpg").autoOrient()
gm("img.png").average()
gm("img.png").backdrop()
Specifies the number of bits of color to preserve in the image. See the docs for more detail.
gm("img.png").bitdepth(bits)
pixels below `threshold` become black.
gm("img.png").blackThreshold(red [,green] [,blue] [,opacity])
gm("img.png").bluePrimary(x, x)
Accepts a radius
and optional sigma
(standard deviation).
gm("img.png").blur(radius [, sigma])
gm("img.png").border(width, height)
gm("img.png").borderColor(color)
gm("img.png").box(color)
type
gm("img.png").channel(type)
Simulates a charcoal drawing. Accepts a factor
.
gm("img.png").charcoal(factor)
Removes pixels from the interior of an image.
gm("img.png").chop(width, height, x, y)
gm("img.png").clip()
gm("img.png").coalesce()
Colorize the image with optionally separate red, green, and blue values.
gm("img.png").colorize(red [, green [, blue]])
type
gm("img.png").colorMap(type)
Sets the preferred number of colors for the image (color reduction).
gm("img.png").colors(int)
Specifies the type of colorspace. See the GraphicsMagick
docs for val
details.
gm("img.png").colorspace(val)
gm("img.png").compose(operator)
type
gm("img.png").compress(type)
Annotates an image. See the docs for more info.
gm("img.png").comment(text|format)
Increases or reduces the image contrast. Accepts a multiplier.
gm("img.png").contrast([+-]multiplier)
gm("img.png").convolve(kernel)
gm("img.png").createDirectories()
Crops the image to the given width
and height
at the given x
and y
position.
gm("img.png").crop(width, height, x, y)
Displace the image colormap by amount. amount
is the number of positions each colormap entry is shifted.
gm("img.png").cycle(amount)
gm("img.png").deconstruct()
gm("img.png").define()
`amount` is in hundreths of a second.
gm("img.png").delay(amout)
This option specifies the image resolution to store while encoding a raster image or the canvas resolution while rendering (reading) vector formats into an image.
gm("img.png").density(width, height)
Reduces the speckles within the image.
gm("img.png").despeckle()
Shift image pixels as defined by a displacement map.
gm("img.png").displace(horizontal, vertical)
gm("img.png").display(value)
gm("img.png").dispose(method)
gm("img.png").dissolve(method)
Applies Floyd/Steinberg error diffusion to the image. Pass false
to disable dithering.
Note: either .colors()
or .monochrome()
must be used for this to take effect.
gm("img.png").dither([bool])
Emphasizes edges in an image. Takes an optional radius
of the emphasis to apply.
gm("img.png").edge([radius])
Embosses the image. Takes an optional radius
.
gm("img.png").emboss([radius])
type
gm("img.png").encoding(type)
type
gm("img.png").endian(type)
Enhances the image.
gm("img.png").enhance()
Performs histogram equalization to the image.
gm("img.png").equalize()
composite image on background color canvas image.
gm("img.png").extent([width, height, options])
gm("img.png").file(filename)
Specifies the filter to use when resizing. see link for available types.
gm("img.png").filter(type)
gm("img.png").flatten()
Creates a mirror image (vertically).
gm("img.png").flip()
Creates a mirror image (horizontally).
gm("img.png").flop()
gm("img.png").foreground(color)
gm("img.png").frame(width, height, outerBevelWidth, innerBevelWidth)
gm("img.png").fuzz(distance [,percent])
Adjusts the level of gamma correction.
gm("img.png").gamma(r, g, b)
gm("img.png").gaussian(radius [,sigma])
gm("img.png").geometry(width, height [,arg])
gm("img.png").greenPrimary(x, y)
The direction the primitive gravitates to when annotating the image. Defaults to NorthWest.
direction
gm("img.png").gravity(direction)
gm("img.png").highlightColor(color)
gm("img.png").highlightStyle(color)
gm("img.png").iconGeometry(geometry)
Implodes the image pixels around the center. Takes an optional factor
.
gm("img.png").implode([factor])
type
gm("img.png").intent(type)
Specifies the type of interlacing scheme. Defaults to None
.
type
gm("img.png").interlace(type)
Assigns a label to an image.
gm("img.png").label(name)
gm("img.png").lat(width, height, offset [,percent])
gm("img.png").level(blackPoint, gamma, whitePoint [,percent])
Sets resource limits.
type
val
gm("img.png").limit(type, val)
type
gm("img.png").list(type)
Specify format for debug log. See the docs for detail.
gm("img.png").log(format)
See the docs for detail.
gm("img.png").loop(iterations)
Creates a pseudo 3D lowering effect of the images edges.
gm("img.png").lower(width, height)
Magnifies the image factor
times.
gm("img.png").magnify(factor)
See the docs for detail.
gm("img.png").map(filename)
See the docs for detail.
gm("img.png").mask(filename)
See the docs for detail.
gm("img.png").matte()
See the docs for detail.
gm("img.png").matteColor(color)
See the docs for detail.
gm("img.png").maximumError(limit)
Applies a median filter to the image. The optional param radius
adjusts the weight of the effect.
gm("img.png").median([radius])
Minifies the image factor
times.
gm("img.png").minify(factor)
See the docs for detail.
gm("img.png").mode(value)
Varies the brightness, saturation, and hue of the image.
gm("img.png").modulate(b [, s [, h]])
See the docs for detail.
gm("img.png").monitor()
Transforms the image to black and white.
gm("img.png").monochrome()
Morphs two images together.
otherImg
outName
callback
callback
will be passed the standard args that .write()
receives.gm("img.png").morph(otherImg, outName, callback)
See the docs for detail.
gm("img.png").mosaic()
See the docs for detail.
gm("img.png").motionBlur(radius [, sigma, angle])
See the docs for detail.
gm("img.png").name()
Replaces every pixel with its complementary color.
gm("img.png").negative()
Add or reduce noise in the image.
radius|type
radius
which adjusts the weight of the effect.gm("img.png").noise(radius|type)
See the docs for detail.
gm("img.png").noop()
See the docs for detail.
gm("img.png").normalize()
See the docs for detail.
gm("img.png").opaque(color)
See the docs for detail.
gm("img.png").operator(channel, operator, rvalue [,percent])
See the docs for detail.
gm("img.png").orderedDither(channelType, NxN)
See the docs for detail.
gm("img.png").outputDirectory(channelType, NxN)
See the docs for detail.
gm("img.png").page(width, height [,arg])
See the docs for detail.
gm("img.png").pause(seconds)
See the docs for detail.
gm("img.png").pen(color)
See the docs for detail.
gm("img.png").ping()
See the docs for detail.
gm("img.png").pointSize(value)
Removes EXIF, ICM, etc profile data.
gm("img.png").noProfile()
type
See the docs for valid types.
gm("img.png").preview(type)
Simulates an oil painting.
gm("img.png").paint(radius)
See the docs for detail.
gm("img.png").process(command)
See the docs for detail.
gm("img.png").profile(filename)
See the docs for detail.
gm("img.png").progress()
See the docs for detail.
gm("img.png").randomThreshold(channelType, LOWxHIGH)
Adjusts the jpeg|miff|png|tiff compression level. val
ranges from 0 to 100 (best).
gm("img.png").quality(val)
Creates a pseudo 3D raising effect of the images edges.
gm("img.png").raise(width, height)
See the docs for detail.
gm("img.png").recolor(matrix)
See the docs for detail.
gm("img.png").redPrimary(x, y)
Specifies that all following methods only apply to the area specified by width, height, x, y
.
gm("img.png").region(width, height, x, y).sepia()
In this case, the sepia effect would only be applied within the area specified by width, height, x, y
.
See the docs for detail.
gm("img.png").remote()
See the docs for detail.
gm("img.png").render()
See the docs for detail.
gm("img.png").repage(width, height, xoff, yoff, arg)
See the docs for detail.
gm("img.png").sample(geometry)
See the docs for detail.
gm("img.png").samplingFactor(horizontalFactor, verticalFactor)
See the docs for detail.
gm("img.png").rawSize(width, height, offset)
Resamples the image to specified horizontal and vertical resolution.
gm("img.png").resample(horizontal, vertical)
Resize the image.
options
%, @, !, < or >
see the GraphicsMagick docs for detailsgm("img.png").resize(width [, height [, options]])
To resize an image to a width of 40px while maintaining aspect ratio: gm("img.png").resize(40)
To resize an image to a height of 50px while maintaining aspect ratio: gm("img.png").resize(null, 50)
To resize an image to a fit a 40x50 rectangle while maintaining aspect ratio: gm("img.png").resize(40, 50)
To override the image's proportions and force a resize to 40x50: gm("img.png").resize(40, 50, "!")
Rolls an image vertically or horizontally.
gm("img.png").roll(horizontalInt, verticalInt)
Rotates the image by degrees
and fills the background with color
.
gm("img.png").rotate(color, degrees)
See the docs for detail.
gm("img.png").scene(value)
See the docs for detail.
gm("img.png").scenes(start, end)
Scales the image.
gm("img.png").scale(width, height)
See the docs for detail.
gm("img.png").screen()
See the docs for detail.
gm("img.png").segment(clusterThreshold, smoothingThreshold)
Helpful if we process a large .gif so we don't load in memory each frame.
gm("img.png").selectFrame(0)
A convenience method to apply a sepia effect to the image.
gm("img.png").sepia()
See the docs for detail.
gm("img.png").set(attribute, value)
Overriddes the output image format.
Helpful if we are outputting an image with no extention but need to change formats.
gm("img.png").setFormat(format)
See the docs for detail.
gm("img.png").shade(azimuth, elevation)
See the docs for detail.
gm("img.png").shadow(radius, sigma)
See the docs for detail.
gm("img.png").shave(width, height, percent)
See the docs for detail.
gm("img.png").shear(xDegrees, yDegrees)
See the docs for detail.
gm("img.png").silent()
See the docs for detail.
gm("img.png").snaps(value)
Negates all pixels above threshold
percent.
gm("img.png").solarize(threshold)
Desplaces pixels by a random amount
.
gm("img.png").spread(amount)
See the docs for detail.
gm("img.png").stegano(offset)
See the docs for detail.
gm("img.png").stereo()
Strips the image of any profiles or comments.
Similar to noProfile() but removes both profile and comment data. only works with imageMagick.
gm("img.png").strip()
Swirls pixels arount the center of the image. degrees
specifies the tightness of the swirl.
gm("img.png").swirl(degrees)
See the docs for detail.
gm("img.png").textFont(font)
See the docs for detail.
gm("img.png").texture(font)
See the docs for detail.
gm("img.png").threshold(value [, percent])
Creates a thumbnail based on minimum sizes.
width
height
outName
quality
callback
.write(err, stdout, stderr, command)
receives.gm("img.png").thumb(width, height, outName, quality, callback)
See the docs for detail.
gm("img.png").tile(filename)
See the docs for detail.
gm("img.png").title(string)
See the docs for detail.
gm("img.png").transform(color)
See the docs for detail.
gm("img.png").transparent(color)
See the docs for detail.
gm("img.png").treeDepth(color)
Trim an image by removing any edges that are exactly the same color as the corner pixels.
gm("img.png").trim()
Specifies the image type.
type
gm("img.png").type(type)
See the docs for detail.
gm("img.png").update(seconds)
See the docs for detail.
gm("img.png").units(type)
See the docs for detail.
gm("img.png").unsharp(radius [, sigma, amount, threshold])
See the docs for detail.
gm("img.png").usePixmap()
See the docs for detail.
gm("img.png").view()
See the docs for detail.
gm("img.png").virtualPixel(method)
See the docs for detail.
gm("img.png").visual(type)
See the docs for detail.
gm("img.png").watermark(brightness, saturation)
See the docs for detail.
gm("img.png").wave(amplitude, wavelength)
See the docs for detail.
gm("img.png").whitePoint(x, y)
See the docs for detail.
gm("img.png").whiteThreshold(red, green, blue, opacity)
See the docs for detail.
gm("img.png").window(id)
See the docs for detail.
gm("img.png").windowGroup()
All getters have the same signature:
gm("image.png").size(function(err, value){
// note : value may be undefined
})
size
- returns the size (WxH) of the imageformat
- returns the image format (gif, jpeg, png, etc)depth
- returns the image color depthcolor
- returns the number of colorsres
- returns the image resolutionfilesize
- returns image filesizeidentify
- returns all image data availableorientation
- returns the EXIF orientation of the imageTake a look at drawing.js for examples.
Annotate an image with one or more graphic primitives (shapes, text, transformations, pixel operations). Used internally for all drawing methods.
gm("img.png").draw(args)
Inscribe an elliptical arc within a rectangle. Requires a start and end point as well as the degrees of rotation.
gm("img.png").drawArc(x0, y0, x1, y1, r0, r1)
Draw a Bezier curve.
gm("img.png").drawBezier([x0, y0], ... [xn, yn])
Draws a Circle.
gm("img.png").drawCircle(x0, y0, x1, y1)
Draws an Ellipse.
gm("img.png").drawEllipse(x0, y0, r0, ry, r0, r1)
Draws a Line.
gm("img.png").drawLine(x0, y0, x1, y1)
Draws a Point.
gm("img.png").drawPoint(x, y)
Draws a Polygon.
gm("img.png").drawPolygon([x0, y0] ... [xn, yn])
Draws a Polyline.
gm("img.png").drawPolyline([x0, y0] ... [xn, yn])
Draws a Rectangle. wc
and hc
are optional and add roundness to the corners.
gm("img.png").drawRectangle(x0, y0, x1, y1 [, wc, hc])
Draws text on an image at x/y coordinates.
gm("img.png").drawText(x, y, text [, gravity])
Specifies the color to use when filling a drawn shape.
gm("img.png").fill(color)
Specifies the font to use when you drawText
.
gm("img.png").font(name)
Specifies the font size to use when you drawText
.
gm("img.png").fontSize(size)
Specifies the color to use when stroking a drawn shape.
gm("img.png").stroke(color [, width])
Specifies the stroke width to use when stroking a drawn shape.
gm("img.png").strokeWidth(width)
Sets drawing properties. property
can be either "color" or "matte".
gm("img.png").setDraw(property, x, y, method)
Both GraphicsMagick and ImageMagick support image comparisons which are exposed through gm.compare()
.
Currently both path1
and path2
must be strings (no Buffers or Streams). Optionally pass a custom
tolerance
level if 0.4
(the default) is too lax for your use case.
Your callback
will be passed four arguments:
gm.compare(path1, path2, function (err, isEqual, equality, raw) {
if (err) throw err;
console.log('The images are equal: %s', isEqual);
console.log('Actual equality: %d', equality)
console.log('Raw output was: %j', raw);
});
You can also output a diff image of the two images by passing a configuration object in place of the tolerance:
var options = {
highlightColor: 'yellow', // optional. Defaults to red
file: './diff.png' // required
};
gm.compare(path1, path2, options, function (err) {
if (err) throw err;
});
We have compatibility with ImageMagick too. Just subclass the gm constructor passing the imageMagick option.
var imageMagick = gm.subClass({ imageMagick: true });
Then use imageMagick
the same way you'd normally use gm
.
imageMagick("img.png").autoOrient().write('/path', callback);
Unlike GraphicsMagick, ImageMagick supports the WebP format. However, you must compile ImageMagick with the WebP option. To do so on OS X, install ImageMagick with the following command using Homebrew:
brew install imagemagick --with-webp
If you have already installed ImageMagick, you would have to uninstall it then reinstall it.