Browse files

Node v.0.5.2 and above fix

  • Loading branch information...
1 parent e766673 commit b9580efd05d09011c56991dcdbb80cc5703c9f54 @dudochkin-victor dudochkin-victor committed Mar 21, 2012
Showing with 96 additions and 14 deletions.
  1. +1 −1 README
  2. +42 −0 README.md
  3. +12 −5 gd.js
  4. +25 −3 gd_bindings.cc
  5. +12 −0 package.json
  6. +3 −4 test.js
  7. BIN test.png
  8. +1 −1 wscript
View
2 README
@@ -2,4 +2,4 @@ GD bindings for Node.js
==================================
GD graphic library bindings for Node.js supporting asynchronous I/O.
-Tested with Node v0.4.6
+Tested with Node v0.4.6 & v0.6.6 (by Dudochkin Victor <blacksmith@gogoo.ru>)
View
42 README.md
@@ -0,0 +1,42 @@
+#GD bindings for Node.js
+*GD graphic library bindings for Node.js supporting asynchronous I/O written in C/C++*.
+
+Tested with Node v0.4.6 & v0.6.6 (by Dudochkin Victor <blacksmith@gogoo.ru>)
+
+## Install:
+### Using npm
+
+npm install gd
+
+### From sources
+1) go to the directory with GD (this library :) )
+
+2) execute `node-waf configure build`
+
+3) Put it in node_modules.
+
+## Using GD
+
+var fs = require('fs');
+var path = require('path');
+var gd = require('gd');
+
+var source = './test.png';
+var target = './test.thumb.png';
+
+if (path.exists(target)) fs.unlink(target);
+
+gd.openPng(
+ source,
+ function(png, path) {
+ if(png) {
+ var w = Math.floor(png.width/2), h = Math.floor(png.height/2);
+ var target_png = gd.createTrueColor(w, h);
+
+ png.copyResampled(target_png,0,0,0,0,w,h,png.width,png.height);
+ target_png.savePng(target, 1, gd.noop);
+ }
+ }
+);
+
+That's all folks!
View
17 gd.js
@@ -14,10 +14,16 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-var
- sys = require('sys'),
- fs = require('fs'),
- bind = require('./gd_bindings');
+var fs = require('fs');
+
+try {
+ // node 0.6+
+ var bind = require('./build/Release/gd_bindings');
+} catch (e) {
+ // node 0.4.x
+ var bind = require('./build/default/gd_bindings');
+}
+
for(var p in bind) {
if (bind[p] !== undefined) exports[p] = bind[p];
@@ -35,6 +41,8 @@ var formats = {
function open_func(format, len) {
return function() {
+ if (!(arguments instanceof Array))
+ arguments = Array.prototype.slice.call(arguments);
var args = [].concat(arguments);
var filename = args.shift();
var callback = args[len-1];
@@ -59,7 +67,6 @@ function save_func(format, len) {
var args = [].concat(arguments);
var filename = args.shift();
var callback = args[len-1];
-
if (typeof callback != 'function') {
return this[format].apply(this, arguments);
}
View
28 gd_bindings.cc
@@ -16,7 +16,24 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <gd.h>
#include <v8.h>
#include <node.h>
+
+/*
+nodejs before v0.5.2 has node_events.h. v0.5.2 and above doesn't have
+JUST WORK FIX by Dudochkin Victor <blacksmith@gogoo.ru>
+*/
+
+#include <node_version.h>
+
+#if ((NODE_MINOR_VERSION <= 5) && (NODE_PATCH_VERSION < 2))
+#define HAVE_NODE_EVENTS
+#endif
+
+#ifdef HAVE_NODE_EVENTS
#include <node_events.h>
+#else
+#include <node_object_wrap.h>
+#endif
+
#include <string.h>
#include <assert.h>
@@ -240,8 +257,12 @@ class Gd
return scope.Close(result);
}
-
+
+#ifdef HAVE_NODE_EVENTS
class Image : public EventEmitter
+#else
+ class Image : public ObjectWrap
+#endif
{
public:
static Persistent<FunctionTemplate> constructor_template;
@@ -251,9 +272,10 @@ class Gd
Local<FunctionTemplate> t = FunctionTemplate::New(New);
constructor_template = Persistent<FunctionTemplate>::New(t);
-
+#ifdef HAVE_NODE_EVENTS
t->Inherit(EventEmitter::constructor_template);
- t->InstanceTemplate()->SetInternalFieldCount(1);
+#endif
+ t->InstanceTemplate()->SetInternalFieldCount(1);
NODE_SET_PROTOTYPE_METHOD(t, "jpeg", Jpeg);
NODE_SET_PROTOTYPE_METHOD(t, "jpegPtr", JpegPtr);
View
12 package.json
@@ -0,0 +1,12 @@
+{
+ "name": "gd",
+ "author": "Taegon Kim",
+ "description": "GD bindings for Node.js",
+ "version": "0.0.2",
+ "contributors": [
+ { "name": "Taegon Kim", "email": "gonom9@gmail.com" },
+ { "name": "Dudochkin Victor", "email": "<blacksmith@gogoo.ru>" }
+ ],
+ "main": "./gd.js",
+ "engines": { "node": ">= 0.4.8" }
+}
View
7 test.js
@@ -1,11 +1,10 @@
-#!/usr/local/bin/node
-var sys = require('sys');
+#!/usr/bin/node
var fs = require('fs');
var path = require('path');
var gd = require('./gd');
-var source = './funnyfog.png';
-var target = './funnyfog.thumb.png';
+var source = './test.png';
+var target = './test.thumb.png';
if (path.exists(target)) fs.unlink(target);
View
BIN test.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
2 wscript
@@ -4,7 +4,7 @@ from os.path import exists
srcdir = "."
blddir = "build"
-VERSION = "0.0.1"
+VERSION = "0.0.2"
def set_options(opt):
opt.tool_options("compiler_cxx")

0 comments on commit b9580ef

Please sign in to comment.