get-image-data
Advanced tools
Comparing version 3.0.1 to 4.0.0
@@ -1,26 +0,25 @@ | ||
var get = require('get-image') | ||
var shared = require('./shared') | ||
var canvas = document.createElement('canvas') | ||
var canvas = null | ||
var supported = (function(document) { | ||
canvas = document.createElement('canvas') | ||
return !!( | ||
canvas.getContext && | ||
canvas.getContext('2d') | ||
) | ||
})(document) | ||
module.exports = get | ||
module.exports = function(path, callback) { | ||
if (!supported) { | ||
return callback(new Error( | ||
'Your browser doesn’t the ' + | ||
'<canvas> element' | ||
)) | ||
function get (src, cb) { | ||
var img = new Image | ||
if (!/^data/.test(src)) | ||
img.crossOrigin = '' | ||
img.src = src | ||
img.onerror = cb | ||
img.onload = function () { | ||
data(img, cb) | ||
} | ||
} | ||
get(path, function(error, image) { | ||
error ? | ||
callback(error) : | ||
callback(null, shared(canvas)(image)) | ||
}) | ||
function data (img, cb) { | ||
var ctx = canvas.getContext('2d') | ||
canvas.width = img.width | ||
canvas.height = img.height | ||
ctx.drawImage(img, 0, 0) | ||
cb(null, ctx.getImageData( | ||
0, 0, img.width, img.height | ||
)) | ||
} |
{ | ||
"name": "get-image-data", | ||
"version": "3.0.1", | ||
"description": "A browser/server utility that extracts RGBA data from images.", | ||
"main": "index.js", | ||
"author": "Michael Rhodes", | ||
"version": "4.0.0", | ||
"main": "node.js", | ||
"browser": "browser.js", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"get-image": "~2.0.0" | ||
"jimp": "^0.6.0" | ||
}, | ||
"peerDependencies": { | ||
"canvas": "~1.6.2" | ||
"sharp": "^0.21.3" | ||
}, | ||
"devDependencies": { | ||
"tape": "~2.1.0", | ||
"testling": "~1.7.1", | ||
"brfs": "~0.0.8" | ||
"brfs": "^2.0.1", | ||
"dexy": "github:michaelrhodes/dexy", | ||
"wzrd": "^1.5.0" | ||
}, | ||
"scripts": { | ||
"test": "tape ./test/server.js", | ||
"test:browser": "testling -u" | ||
}, | ||
"testling": { | ||
"files": "./test/browser.js", | ||
"browsers": { | ||
"ie": [8, 9, 10], | ||
"chrome": [20, 25, 29], | ||
"firefox": [4, 19, 24], | ||
"safari": [5.1, 6], | ||
"opera": [10, 12, 15], | ||
"iphone": [6], | ||
"android": [4.2] | ||
} | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:michaelrhodes/get-image-data.git" | ||
}, | ||
"keywords": [ | ||
"image", | ||
"data", | ||
"rgba" | ||
], | ||
"author": "Michael Rhodes", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/michaelrhodes/get-image-data/issues" | ||
"test": "dexy test/node.js", | ||
"test:native": "dexy test/native.js", | ||
"test:browser": "wzrd test/browser.js -t brfs" | ||
} | ||
} |
# get-image-data | ||
get-image-data is a browser/server utility that extracts RGBA data from images. It also provides the image’s height and width. | ||
isomorphic image data extraction | ||
[![Build status](https://travis-ci.org/michaelrhodes/get-image-data.svg?branch=master)](https://travis-ci.org/michaelrhodes/get-image-data) | ||
[![build status](https://travis-ci.org/michaelrhodes/get-image-data.svg?branch=master)](https://travis-ci.org/michaelrhodes/get-image-data) | ||
[![Browser support](https://ci.testling.com/michaelrhodes/get-image-data.png)](https://ci.testling.com/michaelrhodes/get-image-data) | ||
[![browser support](https://ci.testling.com/michaelrhodes/get-image-data.png)](https://ci.testling.com/michaelrhodes/get-image-data) | ||
## Install | ||
## install | ||
``` sh | ||
$ npm install get-image-data | ||
npm install get-image-data [sharp] | ||
``` | ||
**note: canvas is not installed alongside get-image-data** | ||
get-image-data requires [automattic/node-canvas](https://github.com/automattic/node-canvas) for its server/node variant, however, to avoid browser-only users from having to endure the native compilation process, it needs to be npm installed separately. | ||
## Usage | ||
### Browser & Server | ||
## use | ||
``` js | ||
var image = require('get-image-data') | ||
image('./image.jpg', function(error, info) { | ||
image('./image.jpg', function (err, info) { | ||
var data = info.data | ||
var height = info.height | ||
var width = info.width | ||
var data = info.data | ||
@@ -36,9 +29,14 @@ for (var i = 0, l = data.length; i < l; i += 4) { | ||
}) | ||
// Extract data faster with `sharp` | ||
var image = require('get-image-data/native') | ||
``` | ||
### Note | ||
The image data will be contained within either a [Uint8ClampedArray](https://developer.mozilla.org/en-US/docs/Web/API/Uint8ClampedArray) or a [CanvasPixelArray](https://developer.mozilla.org/en-US/docs/Web/API/CanvasPixelArray) depending on the environment. This shouldn’t be a problem, but it’s worth knowing. | ||
## obey | ||
Copyright 2013–2019 Michael Rhodes | ||
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: | ||
### License | ||
[MIT](http://opensource.org/licenses/MIT) | ||
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. |
var fs = require('fs') | ||
var data = require('../browser') | ||
var get = require('../browser') | ||
require('./shared')(data, { | ||
require('./runner')(get, { | ||
trad: fs.readFileSync(__dirname + '/images/trad.txt'), | ||
@@ -6,0 +6,0 @@ jerry: fs.readFileSync(__dirname + '/images/jerry.txt'), |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1105977
122
1
42
4
1
+ Addedjimp@^0.6.0
+ Added@jimp/bmp@0.6.8(transitive)
+ Added@jimp/core@0.6.8(transitive)
+ Added@jimp/custom@0.6.8(transitive)
+ Added@jimp/gif@0.6.8(transitive)
+ Added@jimp/jpeg@0.6.8(transitive)
+ Added@jimp/plugin-blit@0.6.8(transitive)
+ Added@jimp/plugin-blur@0.6.8(transitive)
+ Added@jimp/plugin-color@0.6.8(transitive)
+ Added@jimp/plugin-contain@0.6.8(transitive)
+ Added@jimp/plugin-cover@0.6.8(transitive)
+ Added@jimp/plugin-crop@0.6.8(transitive)
+ Added@jimp/plugin-displace@0.6.8(transitive)
+ Added@jimp/plugin-dither@0.6.8(transitive)
+ Added@jimp/plugin-flip@0.6.8(transitive)
+ Added@jimp/plugin-gaussian@0.6.8(transitive)
+ Added@jimp/plugin-invert@0.6.8(transitive)
+ Added@jimp/plugin-mask@0.6.8(transitive)
+ Added@jimp/plugin-normalize@0.6.8(transitive)
+ Added@jimp/plugin-print@0.6.8(transitive)
+ Added@jimp/plugin-resize@0.6.8(transitive)
+ Added@jimp/plugin-rotate@0.6.8(transitive)
+ Added@jimp/plugin-scale@0.6.8(transitive)
+ Added@jimp/plugins@0.6.8(transitive)
+ Added@jimp/png@0.6.8(transitive)
+ Added@jimp/tiff@0.6.8(transitive)
+ Added@jimp/types@0.6.8(transitive)
+ Added@jimp/utils@0.6.8(transitive)
+ Addedansi-regex@2.1.1(transitive)
+ Addedany-base@1.1.0(transitive)
+ Addedaproba@1.2.0(transitive)
+ Addedare-we-there-yet@1.1.7(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbindings@1.5.0(transitive)
+ Addedbl@4.1.0(transitive)
+ Addedbmp-js@0.1.0(transitive)
+ Addedbuffer@5.7.1(transitive)
+ Addedbuffer-equal@0.0.1(transitive)
+ Addedcentra@2.7.0(transitive)
+ Addedchownr@1.1.4(transitive)
+ Addedcode-point-at@1.1.0(transitive)
+ Addedcolor@3.2.1(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedcolor-string@1.9.1(transitive)
+ Addedconsole-control-strings@1.1.0(transitive)
+ Addedcore-js@2.6.12(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddecompress-response@4.2.1(transitive)
+ Addeddeep-extend@0.6.0(transitive)
+ Addeddelegates@1.0.0(transitive)
+ Addeddetect-libc@1.0.3(transitive)
+ Addeddom-walk@0.1.2(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedexif-parser@0.1.12(transitive)
+ Addedexpand-template@2.0.3(transitive)
+ Addedfile-type@9.0.0(transitive)
+ Addedfile-uri-to-path@1.0.0(transitive)
+ Addedfollow-redirects@1.15.9(transitive)
+ Addedfs-constants@1.0.0(transitive)
+ Addedfs-copy-file-sync@1.1.1(transitive)
+ Addedfs-minipass@1.2.7(transitive)
+ Addedgauge@2.7.4(transitive)
+ Addedgithub-from-package@0.0.0(transitive)
+ Addedglobal@4.4.0(transitive)
+ Addedhas-unicode@2.0.1(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedini@1.3.8(transitive)
+ Addedis-arrayish@0.3.2(transitive)
+ Addedis-fullwidth-code-point@1.0.0(transitive)
+ Addedis-function@1.0.2(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedjimp@0.6.8(transitive)
+ Addedjpeg-js@0.3.7(transitive)
+ Addedload-bmfont@1.4.2(transitive)
+ Addedmime@1.6.0(transitive)
+ Addedmimic-response@2.1.0(transitive)
+ Addedmin-document@2.19.0(transitive)
+ Addedminimist@0.0.81.2.8(transitive)
+ Addedminipass@2.9.0(transitive)
+ Addedminizlib@1.3.3(transitive)
+ Addedmkdirp@0.5.10.5.6(transitive)
+ Addedmkdirp-classic@0.5.3(transitive)
+ Addednapi-build-utils@1.0.2(transitive)
+ Addednode-abi@2.30.1(transitive)
+ Addednoop-logger@0.1.1(transitive)
+ Addednpmlog@4.1.2(transitive)
+ Addednumber-is-nan@1.0.1(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedomggif@1.0.10(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpako@1.0.11(transitive)
+ Addedparse-bmfont-ascii@1.0.6(transitive)
+ Addedparse-bmfont-binary@1.0.6(transitive)
+ Addedparse-bmfont-xml@1.1.6(transitive)
+ Addedparse-headers@2.0.5(transitive)
+ Addedphin@2.9.33.7.1(transitive)
+ Addedpixelmatch@4.0.2(transitive)
+ Addedpngjs@3.4.0(transitive)
+ Addedprebuild-install@5.3.6(transitive)
+ Addedprocess@0.11.10(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedrc@1.2.8(transitive)
+ Addedreadable-stream@2.3.83.6.2(transitive)
+ Addedregenerator-runtime@0.13.11(transitive)
+ Addedsafe-buffer@5.1.25.2.1(transitive)
+ Addedsax@1.4.1(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedsharp@0.21.3(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedsimple-concat@1.0.1(transitive)
+ Addedsimple-get@3.1.1(transitive)
+ Addedsimple-swizzle@0.2.2(transitive)
+ Addedstring-width@1.0.2(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedstrip-json-comments@2.0.1(transitive)
+ Addedtar@4.4.19(transitive)
+ Addedtar-fs@2.1.2(transitive)
+ Addedtar-stream@2.2.0(transitive)
+ Addedtimm@1.7.1(transitive)
+ Addedtinycolor2@1.6.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedutif@2.0.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwhich-pm-runs@1.1.0(transitive)
+ Addedwide-align@1.1.5(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedxhr@2.6.0(transitive)
+ Addedxml-parse-from-string@1.0.1(transitive)
+ Addedxml2js@0.5.0(transitive)
+ Addedxmlbuilder@11.0.1(transitive)
+ Addedxtend@4.0.2(transitive)
+ Addedyallist@3.1.1(transitive)
- Removedget-image@~2.0.0
- Removedcanvas@1.6.13(transitive)
- Removedget-image@2.0.0(transitive)