gm ¶
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
图像构造函数.
gm(path)
When you pass a string as the first argument it is interpreted as the path to an image you intend to manipulate.gm(stream || buffer, [filename])
You may also pass a ReadableStream or Buffer as the first argument, with an optional file name for format inference.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
- adjoin
- affine
- antialias
- append
- authenticate
- autoOrient
- average
- backdrop
- bitdepth
- blackThreshold
- bluePrimary
- blur
- border
- borderColor
- box
- channel
- charcoal
- chop
- clip
- coalesce
- colors
- colorize
- colorMap
- colorspace
- comment
- compose
- compress
- contrast
- convolve
- createDirectories
- crop
- cycle
- deconstruct
- delay
- define
- density
- despeckle
- dither
- displace
- display
- dispose
- dissolve
- edge
- emboss
- encoding
- enhance
- endian
- equalize
- extent
- file
- filter
- flatten
- flip
- flop
- foreground
- frame
- fuzz
- gamma
- gaussian
- geometry
- gravity
- greenPrimary
- highlightColor
- highlightStyle
- iconGeometry
- implode
- intent
- interlace
- label
- lat
- level
- list
- limit
- log
- loop
- lower
- magnify
- map
- matte
- matteColor
- mask
- maximumError
- median
- minify
- mode
- modulate
- monitor
- monochrome
- morph
- mosaic
- motionBlur
- name
- negative
- noise
- noop
- normalize
- noProfile
- opaque
- operator
- orderedDither
- outputDirectory
- paint
- page
- pause
- pen
- ping
- pointSize
- preview
- process
- profile
- progress
- quality
- raise
- rawSize
- randomThreshold
- recolor
- redPrimary
- region
- remote
- render
- repage
- resample
- resize
- roll
- rotate
- sample
- samplingFactor
- scale
- scene
- scenes
- screen
- segment
- sepia
- set
- setFormat
- shade
- shadow
- sharedMemory
- sharpen
- shave
- shear
- silent
- solarize
- snaps
- stegano
- stereo
- strip imagemagick only
- spread
- swirl
- textFont
- texture
- threshold
- thumb
- tile
- transform
- transparent
- treeDepth
- trim
- type
- update
- units
- unsharp
- usePixmap
- view
- virtualPixel
- visual
- watermark
- wave
- whitePoint
- whiteThreshold
- window
- windowGroup
绘画
图像输出
- 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.
贡献¶
灵感¶
插件¶
证书¶
(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.