Welis Garagen-Anzeige
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
||||
lib-cov
|
||||
*.seed
|
||||
*.log
|
||||
*.csv
|
||||
*.dat
|
||||
*.out
|
||||
*.pid
|
||||
*.gz
|
||||
|
||||
pids
|
||||
logs
|
||||
results
|
||||
|
||||
npm-debug.log
|
||||
node_modules/*
|
||||
test/*
|
||||
+22
@@ -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.
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
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). Written in 100% JavaScript, works both in browserify and in node.js and has no external native dependencies.
|
||||
|
||||
Currently the following file formats are supported:
|
||||
|
||||
* `PNG`
|
||||
* `JPEG`
|
||||
* `GIF`
|
||||
|
||||
Example
|
||||
=======
|
||||
|
||||
```javascript
|
||||
var getPixels = require("get-pixels")
|
||||
|
||||
getPixels("lena.png", function(err, pixels) {
|
||||
if(err) {
|
||||
console.log("Bad image path")
|
||||
return
|
||||
}
|
||||
console.log("got pixels", pixels.shape.slice())
|
||||
})
|
||||
```
|
||||
|
||||
Install
|
||||
=======
|
||||
|
||||
npm install get-pixels
|
||||
|
||||
### `require("get-pixels")(url[, type], cb(err, pixels))`
|
||||
Reads all the pixels from url into an ndarray.
|
||||
|
||||
* `url` is the path to the file. It can be a relative path, an http url, a data url, or an [in-memory Buffer](http://nodejs.org/api/buffer.html).
|
||||
* `type` is an optional mime type for the image (required when using a Buffer)
|
||||
* `cb(err, pixels)` is a callback which gets triggered once the image is loaded.
|
||||
|
||||
**Returns** An ndarray of pixels in raster order having shape equal to `[width, height, channels]`.
|
||||
|
||||
**Note** For animated GIFs, a 4D array is returned with shape `[numFrames, width, height, 4]`, where each frame is a slice of the final array.
|
||||
|
||||
Credits
|
||||
=======
|
||||
(c) 2013-2014 Mikola Lysenko. MIT License
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
'use strict'
|
||||
|
||||
var path = require('path')
|
||||
var ndarray = require('ndarray')
|
||||
var GifReader = require('omggif').GifReader
|
||||
var pack = require('ndarray-pack')
|
||||
var through = require('through')
|
||||
var parseDataURI = require('data-uri-to-buffer')
|
||||
|
||||
function defaultImage(url, cb) {
|
||||
var img = new Image()
|
||||
img.crossOrigin = "Anonymous"
|
||||
img.onload = function() {
|
||||
var canvas = document.createElement('canvas')
|
||||
canvas.width = img.width
|
||||
canvas.height = img.height
|
||||
var context = canvas.getContext('2d')
|
||||
context.drawImage(img, 0, 0)
|
||||
var pixels = context.getImageData(0, 0, img.width, img.height)
|
||||
cb(null, ndarray(new Uint8Array(pixels.data), [img.width, img.height, 4], [4, 4*img.width, 1], 0))
|
||||
}
|
||||
img.onerror = function(err) {
|
||||
cb(err)
|
||||
}
|
||||
img.src = url
|
||||
}
|
||||
|
||||
//Animated gif loading
|
||||
function handleGif(data, cb) {
|
||||
var reader
|
||||
try {
|
||||
reader = new GifReader(data)
|
||||
} catch(err) {
|
||||
cb(err)
|
||||
return
|
||||
}
|
||||
if(reader.numFrames() > 0) {
|
||||
var nshape = [reader.numFrames(), reader.height, reader.width, 4]
|
||||
var ndata = new Uint8Array(nshape[0] * nshape[1] * nshape[2] * nshape[3])
|
||||
var result = ndarray(ndata, nshape)
|
||||
try {
|
||||
for(var i=0; i<reader.numFrames(); ++i) {
|
||||
reader.decodeAndBlitFrameRGBA(i, ndata.subarray(
|
||||
result.index(i, 0, 0, 0),
|
||||
result.index(i+1, 0, 0, 0)))
|
||||
}
|
||||
} catch(err) {
|
||||
cb(err)
|
||||
return
|
||||
}
|
||||
cb(null, result.transpose(0,2,1))
|
||||
} else {
|
||||
var nshape = [reader.height, reader.width, 4]
|
||||
var ndata = new Uint8Array(nshape[0] * nshape[1] * nshape[2])
|
||||
var result = ndarray(ndata, nshape)
|
||||
try {
|
||||
reader.decodeAndBlitFrameRGBA(0, ndata)
|
||||
} catch(err) {
|
||||
cb(err)
|
||||
return
|
||||
}
|
||||
cb(null, result.transpose(1,0))
|
||||
}
|
||||
}
|
||||
|
||||
function httpGif(url, cb) {
|
||||
var xhr = new XMLHttpRequest()
|
||||
xhr.open('GET', url, true)
|
||||
xhr.responseType = 'arraybuffer'
|
||||
if(xhr.overrideMimeType){
|
||||
xhr.overrideMimeType('application/binary')
|
||||
}
|
||||
xhr.onerror = function(err) {
|
||||
cb(err)
|
||||
}
|
||||
xhr.onload = function() {
|
||||
if(xhr.readyState !== 4) {
|
||||
return
|
||||
}
|
||||
var data = new Uint8Array(xhr.response)
|
||||
handleGif(data, cb)
|
||||
return
|
||||
}
|
||||
xhr.send()
|
||||
}
|
||||
|
||||
function copyBuffer(buffer) {
|
||||
if(buffer[0] === undefined) {
|
||||
var n = buffer.length
|
||||
var result = new Uint8Array(n)
|
||||
for(var i=0; i<n; ++i) {
|
||||
result[i] = buffer.get(i)
|
||||
}
|
||||
return result
|
||||
} else {
|
||||
return new Uint8Array(buffer)
|
||||
}
|
||||
}
|
||||
|
||||
function dataGif(url, cb) {
|
||||
process.nextTick(function() {
|
||||
try {
|
||||
var buffer = parseDataURI(url)
|
||||
if(buffer) {
|
||||
handleGif(copyBuffer(buffer), cb)
|
||||
} else {
|
||||
cb(new Error('Error parsing data URI'))
|
||||
}
|
||||
} catch(err) {
|
||||
cb(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = function getPixels(url, type, cb) {
|
||||
if(!cb) {
|
||||
cb = type
|
||||
type = ''
|
||||
}
|
||||
var ext = path.extname(url)
|
||||
switch(type || ext.toUpperCase()) {
|
||||
case '.GIF':
|
||||
httpGif(url, cb)
|
||||
break
|
||||
default:
|
||||
if(Buffer.isBuffer(url)) {
|
||||
url = 'data:' + type + ';base64,' + url.toString('base64')
|
||||
}
|
||||
if(url.indexOf('data:image/gif;') === 0) {
|
||||
dataGif(url, cb)
|
||||
} else {
|
||||
defaultImage(url, cb)
|
||||
}
|
||||
}
|
||||
}
|
||||
+188
@@ -0,0 +1,188 @@
|
||||
'use strict'
|
||||
|
||||
var ndarray = require('ndarray')
|
||||
var path = require('path')
|
||||
var PNG = require('pngjs').PNG
|
||||
var jpeg = require('jpeg-js')
|
||||
var pack = require('ndarray-pack')
|
||||
var GifReader = require('omggif').GifReader
|
||||
var Bitmap = require('node-bitmap')
|
||||
var fs = require('fs')
|
||||
var request = require('request')
|
||||
var mime = require('mime-types')
|
||||
var parseDataURI = require('parse-data-uri')
|
||||
|
||||
function handlePNG(data, cb) {
|
||||
var png = new PNG();
|
||||
png.parse(data, function(err, img_data) {
|
||||
if(err) {
|
||||
cb(err)
|
||||
return
|
||||
}
|
||||
cb(null, ndarray(new Uint8Array(img_data.data),
|
||||
[img_data.width|0, img_data.height|0, 4],
|
||||
[4, 4*img_data.width|0, 1],
|
||||
0))
|
||||
})
|
||||
}
|
||||
|
||||
function handleJPEG(data, cb) {
|
||||
var jpegData
|
||||
try {
|
||||
jpegData = jpeg.decode(data)
|
||||
}
|
||||
catch(e) {
|
||||
cb(e)
|
||||
return
|
||||
}
|
||||
if(!jpegData) {
|
||||
cb(new Error("Error decoding jpeg"))
|
||||
return
|
||||
}
|
||||
var nshape = [ jpegData.height, jpegData.width, 4 ]
|
||||
var result = ndarray(jpegData.data, nshape)
|
||||
cb(null, result.transpose(1,0))
|
||||
}
|
||||
|
||||
function handleGIF(data, cb) {
|
||||
var reader
|
||||
try {
|
||||
reader = new GifReader(data)
|
||||
} catch(err) {
|
||||
cb(err)
|
||||
return
|
||||
}
|
||||
if(reader.numFrames() > 0) {
|
||||
var nshape = [reader.numFrames(), reader.height, reader.width, 4]
|
||||
var ndata = new Uint8Array(nshape[0] * nshape[1] * nshape[2] * nshape[3])
|
||||
var result = ndarray(ndata, nshape)
|
||||
try {
|
||||
for(var i=0; i<reader.numFrames(); ++i) {
|
||||
reader.decodeAndBlitFrameRGBA(i, ndata.subarray(
|
||||
result.index(i, 0, 0, 0),
|
||||
result.index(i+1, 0, 0, 0)))
|
||||
}
|
||||
} catch(err) {
|
||||
cb(err)
|
||||
return
|
||||
}
|
||||
cb(null, result.transpose(0,2,1))
|
||||
} else {
|
||||
var nshape = [reader.height, reader.width, 4]
|
||||
var ndata = new Uint8Array(nshape[0] * nshape[1] * nshape[2])
|
||||
var result = ndarray(ndata, nshape)
|
||||
try {
|
||||
reader.decodeAndBlitFrameRGBA(0, ndata)
|
||||
} catch(err) {
|
||||
cb(err)
|
||||
return
|
||||
}
|
||||
cb(null, result.transpose(1,0))
|
||||
}
|
||||
}
|
||||
|
||||
function handleBMP(data, cb) {
|
||||
var bmp = new Bitmap(data)
|
||||
try {
|
||||
bmp.init()
|
||||
} catch(e) {
|
||||
cb(e)
|
||||
return
|
||||
}
|
||||
var bmpData = bmp.getData()
|
||||
var nshape = [ bmpData.getHeight(), bmpData.getWidth(), 4 ]
|
||||
var ndata = new Uint8Array(nshape[0] * nshape[1] * nshape[2])
|
||||
var result = ndarray(ndata, nshape)
|
||||
pack(bmpData, result)
|
||||
cb(null, result.transpose(1,0))
|
||||
}
|
||||
|
||||
|
||||
function doParse(mimeType, data, cb) {
|
||||
switch(mimeType) {
|
||||
case 'image/png':
|
||||
handlePNG(data, cb)
|
||||
break
|
||||
|
||||
case 'image/jpg':
|
||||
case 'image/jpeg':
|
||||
handleJPEG(data, cb)
|
||||
break
|
||||
|
||||
case 'image/gif':
|
||||
handleGIF(data, cb)
|
||||
break
|
||||
|
||||
case 'image/bmp':
|
||||
handleBMP(data, cb)
|
||||
break
|
||||
|
||||
default:
|
||||
cb(new Error("Unsupported file type: " + mimeType))
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = function getPixels(url, type, cb) {
|
||||
if(!cb) {
|
||||
cb = type
|
||||
type = ''
|
||||
}
|
||||
if(Buffer.isBuffer(url)) {
|
||||
if(!type) {
|
||||
cb(new Error('Invalid file type'))
|
||||
return
|
||||
}
|
||||
doParse(type, url, cb)
|
||||
} else if(url.indexOf('data:') === 0) {
|
||||
try {
|
||||
var buffer = parseDataURI(url)
|
||||
if(buffer) {
|
||||
process.nextTick(function() {
|
||||
doParse(type || buffer.mimeType, buffer.data, cb)
|
||||
})
|
||||
} else {
|
||||
process.nextTick(function() {
|
||||
cb(new Error('Error parsing data URI'))
|
||||
})
|
||||
}
|
||||
} catch(err) {
|
||||
process.nextTick(function() {
|
||||
cb(err)
|
||||
})
|
||||
}
|
||||
} else if(url.indexOf('http://') === 0 || url.indexOf('https://') === 0) {
|
||||
request({url:url, encoding:null}, function(err, response, body) {
|
||||
if(err) {
|
||||
cb(err)
|
||||
return
|
||||
}
|
||||
|
||||
type = type;
|
||||
if(!type){
|
||||
if(response.getHeader !== undefined){
|
||||
type = response.getHeader('content-type');
|
||||
}else if(response.headers !== undefined){
|
||||
type = response.headers['content-type'];
|
||||
}
|
||||
}
|
||||
if(!type) {
|
||||
cb(new Error('Invalid content-type'))
|
||||
return
|
||||
}
|
||||
doParse(type, body, cb)
|
||||
})
|
||||
} else {
|
||||
fs.readFile(url, function(err, data) {
|
||||
if(err) {
|
||||
cb(err)
|
||||
return
|
||||
}
|
||||
type = type || mime.lookup(url)
|
||||
if(!type) {
|
||||
cb(new Error('Invalid file type'))
|
||||
return
|
||||
}
|
||||
doParse(type, data, cb)
|
||||
})
|
||||
}
|
||||
}
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"raw": "get-pixels",
|
||||
"scope": null,
|
||||
"escapedName": "get-pixels",
|
||||
"name": "get-pixels",
|
||||
"rawSpec": "",
|
||||
"spec": "latest",
|
||||
"type": "tag"
|
||||
},
|
||||
"/Users/gerrit/Documents/node.js-Projects/tinkerforge"
|
||||
]
|
||||
],
|
||||
"_from": "get-pixels@latest",
|
||||
"_id": "get-pixels@3.3.0",
|
||||
"_inCache": true,
|
||||
"_location": "/get-pixels",
|
||||
"_nodeVersion": "0.12.2",
|
||||
"_npmOperationalInternal": {
|
||||
"host": "packages-6-west.internal.npmjs.com",
|
||||
"tmp": "tmp/get-pixels-3.3.0.tgz_1456159832703_0.4654398539569229"
|
||||
},
|
||||
"_npmUser": {
|
||||
"name": "mikolalysenko",
|
||||
"email": "mikolalysenko@gmail.com"
|
||||
},
|
||||
"_npmVersion": "2.13.1",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"raw": "get-pixels",
|
||||
"scope": null,
|
||||
"escapedName": "get-pixels",
|
||||
"name": "get-pixels",
|
||||
"rawSpec": "",
|
||||
"spec": "latest",
|
||||
"type": "tag"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/get-pixels/-/get-pixels-3.3.0.tgz",
|
||||
"_shasum": "8d9795beae18850b840f749581badc05d3e36e41",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "get-pixels",
|
||||
"_where": "/Users/gerrit/Documents/node.js-Projects/tinkerforge",
|
||||
"author": {
|
||||
"name": "Mikola Lysenko"
|
||||
},
|
||||
"browser": "dom-pixels.js",
|
||||
"bugs": {
|
||||
"url": "https://github.com/scijs/get-pixels/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"data-uri-to-buffer": "0.0.3",
|
||||
"jpeg-js": "^0.1.1",
|
||||
"mime-types": "^2.0.1",
|
||||
"ndarray": "^1.0.13",
|
||||
"ndarray-pack": "^1.1.1",
|
||||
"node-bitmap": "0.0.1",
|
||||
"omggif": "^1.0.5",
|
||||
"parse-data-uri": "^0.2.0",
|
||||
"pngjs": "^2.0.0",
|
||||
"request": "^2.44.0",
|
||||
"through": "^2.3.4"
|
||||
},
|
||||
"description": "Reads the pixels of an image as an ndarray",
|
||||
"devDependencies": {
|
||||
"beefy": "^1.1.0",
|
||||
"brfs": "^1.2.0",
|
||||
"browserify": "^3.44.0",
|
||||
"tape": "^2.12.3"
|
||||
},
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"dist": {
|
||||
"shasum": "8d9795beae18850b840f749581badc05d3e36e41",
|
||||
"tarball": "https://registry.npmjs.org/get-pixels/-/get-pixels-3.3.0.tgz"
|
||||
},
|
||||
"gitHead": "380bbda330666e4a4066c48ef5a42770d13bcd5c",
|
||||
"homepage": "https://github.com/scijs/get-pixels#readme",
|
||||
"keywords": [
|
||||
"ndarray",
|
||||
"pixel",
|
||||
"get",
|
||||
"read",
|
||||
"pixel",
|
||||
"image",
|
||||
"png",
|
||||
"jpeg",
|
||||
"jpg",
|
||||
"jpe",
|
||||
"gif",
|
||||
"decode",
|
||||
"buffer",
|
||||
"data",
|
||||
"parse",
|
||||
"dom",
|
||||
"node",
|
||||
"browserify"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "node-pixels.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "mikolalysenko",
|
||||
"email": "mikolalysenko@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "rreusser",
|
||||
"email": "rsreusser@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "planeshifter",
|
||||
"email": "pgb@andrew.cmu.edu"
|
||||
},
|
||||
{
|
||||
"name": "jaspervdg",
|
||||
"email": "th.v.d.gronde@hccnet.nl"
|
||||
},
|
||||
{
|
||||
"name": "hughsk",
|
||||
"email": "hughskennedy@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "substack",
|
||||
"email": "substack@gmail.com"
|
||||
}
|
||||
],
|
||||
"name": "get-pixels",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/scijs/get-pixels.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tap test/*.js",
|
||||
"test-browser": "beefy test/test.js --open -- -t brfs"
|
||||
},
|
||||
"version": "3.3.0"
|
||||
}
|
||||
Reference in New Issue
Block a user