From 0220d8b865b32c357bb6be1481e972b0fc89cd60 Mon Sep 17 00:00:00 2001 From: Mikola Lysenko Date: Tue, 14 May 2013 16:26:12 -0500 Subject: [PATCH] adding files --- .gitignore | 15 +++++++++++++++ LICENSE | 22 ++++++++++++++++++++++ README.md | 36 ++++++++++++++++++++++++++++++++++++ dom-pixels.js | 23 +++++++++++++++++++++++ node-pixels.js | 6 ++++++ test/test.js | 0 6 files changed, 102 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 dom-pixels.js create mode 100644 node-pixels.js create mode 100644 test/test.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d1b0b0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +lib-cov +*.seed +*.log +*.csv +*.dat +*.out +*.pid +*.gz + +pids +logs +results + +npm-debug.log +node_modules/* \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8ce206a --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ + +The MIT License (MIT) + +Copyright (c) 2013 Mikola Lysenko + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..bfeeb51 --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +get-pixels +========== +Given a URL/path, grab all the pixels in an image and return the result as an [ndarray](https://github.com/mikolalysenko/ndarray). Works both in browserify and in node.js. + +**WORK IN PROGRESS** + +Example +======= + +```javascript +var getPixels = require("get-pixels") + +getPixels("my_image.png", function(err, pixels) { + if(err) { + console.log("Bad image path") + return + } + console.log("got pixels", pixels.shape) +}) +``` + +Install +======= + + npm install get-pixels + +### `require("get-pixels")(url, cb(err, pixels))` +Reads all the pixels from url into an ndarray. + +* `url` is the path to the file +* `cb(err, pixels)` is a callback which gets triggered once the image is loaded. + + +Credits +======= +(c) 2013 Mikola Lysenko. MIT License \ No newline at end of file diff --git a/dom-pixels.js b/dom-pixels.js new file mode 100644 index 0000000..6ef2912 --- /dev/null +++ b/dom-pixels.js @@ -0,0 +1,23 @@ +"use strict" + +var ndarray = require("ndarray") +var ops = require("ndarray-ops") + +module.exports = function getPixels(url, cb) { + var img = new Image() + img.onload = function() { + var canvas = document.createElement("canvas") + canvas.width = img.width + canvas.height = img.height + var context = canvas.getContext("2d") + context.drawImage(img) + var pixels = context.getImageData(0, 0, img.width, img.height) + var buffer = ndarray.zeros([img.width, img.height, 4], "uint8", [1, 2, 0]) + ops.assign(buffer, ndarray.ctor(pixels.data, [img.width, img.height, 4], [4, img.width, 1], 0)) + cb(null, buffer) + } + img.onerror = function(err) { + cb(err) + } + img.src = url +} diff --git a/node-pixels.js b/node-pixels.js new file mode 100644 index 0000000..986e0a8 --- /dev/null +++ b/node-pixels.js @@ -0,0 +1,6 @@ +"use strict" + + + +module.exports = function getPixels(url, cb) { +} \ No newline at end of file diff --git a/test/test.js b/test/test.js new file mode 100644 index 0000000..e69de29