gm Build Status NPM Version

GraphicsMagick 和 ImageMagick 为 node

入门指南

首先需要下载安装 GraphicsMagick 或者 ImageMagick. 在 Mac OS X 里, 你可以很容易的使用 Homebrew 来安装:

brew install imagemagick
brew install graphicsmagick

如果你想要ImageMagick支持WebP, 你必须添加 WebP 选项:

brew install imagemagick --with-webp

或者使用 npm:

npm install gm

或者克隆 repo:

git clone git://github.com/aheckmann/gm.git

构造函数

有很多方法使用 gm 图像构造函数.

  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(stream || buffer, [filename]) You may also pass a ReadableStream or Buffer as the first argument, with an optional file name for format inference.
  3. gm(width, height, [color]) When you pass two integer arguments, gm will create a new image on the fly with the provided dimensions and an optional background color. And you can still chain just like you do with pre-existing images too. See here for an example.

The links below refer to an older version of gm but everything should still work, if anyone feels like updating them please make a PR

方法

获取器 - getters
  • size - returns the size (WxH) of the image
  • orientation - returns the EXIF orientation of the image
  • format - returns the image format (gif, jpeg, png, etc)
  • depth - returns the image color depth
  • color - returns the number of colors
  • res - returns the image resolution
  • filesize - returns image filesize
  • identify - returns all image data available. Takes an optional format string.
操作 - manipulation
绘画
图像输出
  • write - writes the processed image data to the specified filename
  • stream - provides a ReadableStream with the processed image data
  • toBuffer - returns the image as a Buffer instead of a stream

平台的差异

Please document and refer to any platform or ImageMagick/GraphicsMagick issues/differences here.

举例

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.

错误报告

When reporting bugs please include the version of graphicsmagick/imagemagick you're using (gm -version/convert -version) as well as the version of this module and copies of any images you're having problems with.

贡献

contributors

灵感

magickal-node

插件

wiki

证书

(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.