forked from taggon/node-gd
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce mocha, coffee, updated package.json, and proper skeleton
- Loading branch information
1 parent
22d54d5
commit ad2a808
Showing
11 changed files
with
250 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
circle.thumb.png | ||
node_modules/ | ||
build/ | ||
test/fixtures/output.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,43 @@ | ||
GD bindings for Node.js | ||
================================== | ||
# node-gd | ||
|
||
GD graphic library bindings for Node.js supporting asynchronous I/O. | ||
GD graphic library (libgd) C++ bindings for Node.js. | ||
|
||
Original source https://github.com/taggon/node-gd | ||
This version is the community-maintained [official NodeJS.org node-gd repo](https://npmjs.org/package/node-gd). | ||
|
||
Tested with Node v0.4 | ||
## Installation on Debian/Ubuntu | ||
|
||
WARNING | ||
------- | ||
This library is ABANDONWARE; its original author, [Taegon Kim](https://github.com/taggon/node-gd) of South Korea, | ||
stopped loving it over 2 years ago at v0.0.2. This is the community-maintained version currently at v0.1.8, which | ||
you will also find linked as the the [official NodeJS.org node-gd repo](https://npmjs.org/package/node-gd). However, | ||
a word of caution: it's [unusually painful to install](https://github.com/taggon/node-gd/issues/13), and there are better alternatives by now--including: | ||
[node-canvas](https://github.com/LearnBoost/node-canvas), [node-o3-canvas](https://github.com/ajaxorg/node-o3-canvas), | ||
and [node-image](https://github.com/pkrumins/node-image). | ||
|
||
## Install | ||
|
||
npm install node-gd | ||
|
||
## Dependencies | ||
|
||
* **libgd** - in debian install with | ||
|
||
apt-get install libgd2-xpm-dev | ||
```bash | ||
sudo apt-get install libgd2-xpm-dev # libgd | ||
npm install node-gd | ||
``` | ||
|
||
## Usage | ||
|
||
### Require library | ||
```coffeescript | ||
# Require library | ||
gd = require 'node-gd' | ||
|
||
# Create blank new image in memory | ||
output_img = gd.create width, height | ||
|
||
var gd = require("node-gd"); | ||
# Load existing image file on disk into memory | ||
gd.openPng "test.png", (input_img, path) -> | ||
console.log "width: ", input_img.width | ||
console.log "height: ", input_img.width | ||
|
||
### Open file | ||
# Render input over the top of output | ||
input_img.copyResampled output_img, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH | ||
|
||
gd.openPng("test.png", function(png, path){ | ||
console.log("Width: ", png.width); | ||
console.log("Height: ", png.width); | ||
}); | ||
|
||
### Save file | ||
# Write image buffer to disk | ||
output_img.savePng "out.png", 0, -> | ||
console.log "image saved!" | ||
``` | ||
|
||
png.savePng("out.png", 0, function(){ | ||
console.log("image saved!"); | ||
}); | ||
|
||
### Create empty file | ||
As usual, for the latest examples, review the easy-to-follow [./test/test.coffee](https://github.com/mikesmullin/node-gd/blob/master/test/test.coffee). | ||
|
||
var img = gd.create(width, height); | ||
|
||
### Copy image | ||
## Related | ||
|
||
source.copyResampled(dest,dstX,dstY,srcX,srcY,dstW,dstH,srcW,srcH); | ||
* [Original author's repo](https://github.com/taggon/node-gd) | ||
* [node-canvas](https://github.com/LearnBoost/node-canvas) uses libcairo to emulate browser HTML5 Canvas' image manipulation abilities within Node.js | ||
* [node-o3-canvas](https://github.com/ajaxorg/node-o3-canvas) uses libcairo to emulate browser HTML5 Canvas' image manipulation abilities within Node.js | ||
* [node-image](https://github.com/pkrumins/node-image) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# | ||
# Copyright (c) 2009, Taegon Kim <gonom9@gmail.com> | ||
# | ||
# Permission to use, copy, modify, and/or distribute this software for any | ||
# purpose with or without fee is hereby granted, provided that the above | ||
# copyright notice and this permission notice appear in all copies. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
# | ||
|
||
# format : arguments' length [open, save] | ||
open_func = (format, len) -> | ||
return -> | ||
args = Array::slice.call(arguments) | ||
filename = args.shift() | ||
callback = args[len - 1] | ||
return gd_bindings["createFrom" + format].apply(arguments) unless typeof callback is "function" | ||
args.pop() | ||
fs.readFile filename, "binary", (err, data) -> | ||
if err | ||
callback err | ||
else | ||
callback null, gd_bindings["createFrom" + format + "Ptr"](data) | ||
|
||
save_func = (format, len) -> | ||
format = format.toLowerCase() | ||
return -> | ||
args = Array::slice.call(arguments) | ||
filename = args.shift() | ||
callback = args[len - 1] | ||
return this[format].apply(this, arguments) unless typeof callback is "function" | ||
data = this[format + "Ptr"].apply(this, args) | ||
fs.writeFile filename, data, "binary", callback | ||
|
||
util = require 'util' | ||
fs = require 'fs' | ||
|
||
gd_bindings = require __dirname+'/../build/Release/node-gd' | ||
|
||
for p of gd_bindings | ||
if gd_bindings[p] isnt `undefined` | ||
exports[p] = gd_bindings[p] | ||
|
||
formats = | ||
jpeg: [1, 2] | ||
png: [1, 2] | ||
gif: [1, 1] | ||
gd: [1, 1] | ||
gd2: [1, 1] | ||
gd2Part: [5, -1] | ||
WBMP: [1, 1] | ||
|
||
# create wrapper functions | ||
for format of formats | ||
v = formats[format] | ||
format = format.replace /^[a-z]/, (m0) -> | ||
m0.toUpperCase() | ||
exports["open" + format] = open_func(format, v[0]) if v[0] >= 0 | ||
gd_bindings.Image::["save" + format] = save_func(format, v[1]) if v[1] >= 0 |
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,50 @@ | ||
{ | ||
"name" : "node-gd", | ||
"version" : "0.1.8", | ||
"description" : "GD bindings", | ||
"author": "taggon", | ||
"main": "./node-gd", | ||
"scripts": { | ||
"install": "node-gyp configure build" | ||
"name": "node-gd", | ||
"version": "0.2.0", | ||
"description": "libgd C++ bindings for Node.js", | ||
"main": "js/node-gd.js", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"scripts": { | ||
"pretest": "coffee --bare -o js coffee/node-gd.coffee && node-gyp rebuild", | ||
"test": "mocha --reporter spec --bail --ui bdd --colors --compilers coffee:coffee-script --require coffee-script test/test.coffee", | ||
"install": "node-gyp rebuild" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/mikesmullin/node-gd.git" | ||
}, | ||
"keywords": [ | ||
"libgd", | ||
"gd", | ||
"image", | ||
"png", | ||
"jpg", | ||
"gif", | ||
"graphics", | ||
"library" | ||
], | ||
"author": "Taegon Kim <gonom9@gmail.com>", | ||
"license": "MIT", | ||
"contributors": [ | ||
{ | ||
"name": "Dudochkin Victor", | ||
"email": "blacksmith@gogoo.ru" | ||
}, | ||
"repository" : { | ||
"type" : "git", | ||
"url" : "http://github.com/andris9/node-gd.git" | ||
{ | ||
"name": "Andris Reinman", | ||
"email": "andris@node.ee" | ||
}, | ||
{ | ||
"name": "Mike Smullin", | ||
"email": "mike@smullindesign.com" | ||
} | ||
], | ||
"gypfile": true, | ||
"readmeFilename": "README.md", | ||
"devDependencies": { | ||
"mocha": "~1.7.4", | ||
"chai": "~1.4.2" | ||
} | ||
} |
Oops, something went wrong.