mirror of https://gitgud.io/fatchan/gm
commit
defc7360d7
3 changed files with 191 additions and 0 deletions
@ -0,0 +1,84 @@ |
||||
# GM |
||||
GraphicsMagick for node |
||||
|
||||
## getting started |
||||
First download and install "GraphicsMagick":http://www.graphicsmagick.org/ |
||||
|
||||
## example: |
||||
|
||||
gm.convert(image.tempfile) |
||||
.size(120,120) |
||||
.resize(120,120) |
||||
.noProfile() |
||||
.name('/path/to/thumbnails/'+image.filename) |
||||
.write(function(err){ |
||||
if (!err) print('done!') |
||||
} |
||||
|
||||
or |
||||
|
||||
gm.mogrify(image.tempfile) |
||||
.resize(250,400) |
||||
.format("png") |
||||
.size(250,400) |
||||
.dir('/path/to/out') |
||||
.noProfile() |
||||
.write(function(err){ |
||||
if (!err) print('success!') |
||||
}) |
||||
|
||||
## methods |
||||
gm includes light support for the GraphicsMagick `convert` and `mogrify` commands. |
||||
|
||||
- convert |
||||
- name |
||||
- size |
||||
- resize |
||||
- noProfile |
||||
- write |
||||
- makeArgs |
||||
- cmd |
||||
|
||||
- mogrify |
||||
- format |
||||
- dir |
||||
- createDir |
||||
- size |
||||
- resize |
||||
- noProfile |
||||
- write |
||||
- makeArgs |
||||
- cmd |
||||
|
||||
More docs coming soon. |
||||
|
||||
## node version |
||||
Compatible with v0.1.96+ |
||||
|
||||
## insperation |
||||
Inspired by "magickal-node":http://github.com/quiiver/magickal-node |
||||
|
||||
## License |
||||
|
||||
(The MIT License) |
||||
|
||||
Copyright (c) 2010 [Aaron Heckmann](aaron.heckmann+github@gmail.com) |
||||
|
||||
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. |
@ -0,0 +1,96 @@ |
||||
|
||||
// gm - Copyright Aaron Heckmann <aaron.heckmann+github@gmail.com> (MIT Licensed)
|
||||
|
||||
|
||||
var exec = require('child_process').exec |
||||
, gm = {} |
||||
|
||||
|
||||
gm.Image = function(utility, input) { |
||||
this.input = input |
||||
this.inArgs = [utility] |
||||
this.outArgs = [] |
||||
} |
||||
|
||||
gm.Image.prototype =
|
||||
{ size: function(width, height){ |
||||
return this.makeArgs(["-size", width + "x" + height]) |
||||
} |
||||
, _noProfileArg: function(){ |
||||
return ['+profile "*"'] |
||||
} |
||||
, _resizeArg: function(width, height) { |
||||
return ["-resize", width + "x" + height] |
||||
} |
||||
, makeArgs: function(inargs, outargs) { |
||||
if (inargs)
|
||||
this.inArgs = this.inArgs.concat(inargs)
|
||||
if (outargs) |
||||
this.outArgs = this.outArgs.concat(outargs) |
||||
return this |
||||
} |
||||
, cmd: function() { |
||||
return "gm "
|
||||
+ this.inArgs.join(" ") + " "
|
||||
+ this.input + " "
|
||||
+ this.outArgs.join(" ") |
||||
} |
||||
, write: function(callback){ |
||||
var cmd = this.cmd() |
||||
exec(cmd, function(err, stdout, stderr){ |
||||
callback(err, stdout, stderr, cmd); |
||||
}) |
||||
} |
||||
} |
||||
|
||||
|
||||
gm.Mogrify = function(image) { |
||||
gm.Image.call(this, 'mogrify', image) |
||||
} |
||||
function mog() {} |
||||
mog.prototype = gm.Image.prototype |
||||
;(gm.Mogrify.prototype = new mog).constructor = gm.Mogrify |
||||
|
||||
gm.Mogrify.prototype.format = function(format){ |
||||
return this.makeArgs(["-format", format]) |
||||
} |
||||
gm.Mogrify.prototype.dir = function(dir) { |
||||
return this.makeArgs(["-output-directory", dir]) |
||||
} |
||||
gm.Mogrify.prototype.createDir = function(dir) { |
||||
return this.makeArgs(["-create-directories"]) |
||||
} |
||||
gm.Mogrify.prototype.resize = function(width, height){ |
||||
return this.makeArgs(this._resizeArg(width, height)) |
||||
} |
||||
gm.Mogrify.prototype.noProfile = function() { |
||||
return this.makeArgs(this._noProfileArg()) |
||||
} |
||||
|
||||
|
||||
gm.Convert = function(image) { |
||||
gm.Image.call(this, 'convert', image) |
||||
} |
||||
function con(){} |
||||
con.prototype = gm.Image.prototype |
||||
;(gm.Convert.prototype = new con).constructor = gm.Convert |
||||
|
||||
gm.Convert.prototype.resize = function(width, height){ |
||||
return this.makeArgs(null, this._resizeArg(width, height)) |
||||
} |
||||
gm.Convert.prototype.noProfile = function() { |
||||
return this.makeArgs(null, this._noProfileArg()) |
||||
} |
||||
gm.Convert.prototype.name = function(filename) { |
||||
return this.makeArgs(null, [filename]) |
||||
} |
||||
|
||||
|
||||
exports.Image = gm.Image |
||||
|
||||
exports.mogrify = function(image) { |
||||
return new gm.Mogrify(image) |
||||
} |
||||
exports.convert = function(image) { |
||||
return new gm.Convert(image) |
||||
} |
@ -0,0 +1,11 @@ |
||||
{ "name": "gm" |
||||
, "description": "Graphics Magick for node." |
||||
, "version": "0.1.0" |
||||
, "author": "Aaron Heckmann <aaron.heckmann+github@gmail.com>" |
||||
, "keywords": ["nodejs", "graphics magick", "graphics", "magick", "image"] |
||||
, "engines": { "node": ">= 0.1.96" } |
||||
, "directories": { "lib": "./lib"} |
||||
, "bugs": "http://github.com/aheckmann/gm/issues" |
||||
, "licenses": [{ "type": "MIT", "url": "http://www.opensource.org/licenses/mit-license.php"}] |
||||
, "main": "./lib/gm" |
||||
} |
Loading…
Reference in new issue