Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

get-image-data

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-image-data - npm Package Compare versions

Comparing version 3.0.1 to 4.0.0

native.js

41

browser.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc