New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

image-filter-threshold

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

image-filter-threshold - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

.babelrc

27

karma.conf.js

@@ -1,4 +0,6 @@

var istanbul = require('browserify-istanbul');
var istanbul = require('istanbul');
var bistanbul = require('browserify-babel-istanbul');
var babelify = require('babelify');
module.exports = function(config) {
module.exports = function (config) {
config.set({

@@ -30,10 +32,10 @@ singleRun: true,

coverageReporter: {
// specify a common output directory
dir: 'coverage',
reporters: [
// reporters not supporting the `file` property
{ type: 'html', subdir: 'report-html' },
{ type: 'lcov', subdir: 'lcov' },
{ type: 'html', subdir: 'html' },
{ type: 'text-summary' },
{ type: 'lcov'}
]
{ type: 'cobertura', subdir: '.' }
],
sourceStore : istanbul.Store.create('fslookup')
},

@@ -44,5 +46,8 @@

transform: [
'brfs',
istanbul({
ignore: ['**/node_modules/**']
babelify,
bistanbul({
instrumenterConfig: {
noCompact: true
},
ignore: ['**/node_modules/**', '**/tests/**', '**/sandbox/**']
})

@@ -63,4 +68,4 @@ ]

// see what is going on
logLevel: 'LOG_INFO'
logLevel: 'LOG_ERROR'
});
};
{
"name": "image-filter-threshold",
"version": "0.0.6",
"version": "0.0.7",
"description": "Small library to apply a threshold transformation to a image",
"main": "src/index.js",
"scripts": {
"build": "browserify sandbox/sandbox.js > sandbox/bundle.js",
"build": "browserify -t babelify sandbox/sandbox.js > sandbox/bundle.js",
"test": "./node_modules/.bin/karma start",

@@ -33,19 +33,32 @@ "codecov": "cat coverage/*/lcov.info | ./node_modules/codecov.io/bin/codecov.io.js",

"devDependencies": {
"brfs": "^1.4.3",
"browserify": "^13.0.0",
"browserify-istanbul": "^1.0.0",
"chai": "^3.5.0",
"codecov.io": "^0.1.6",
"http-server": "^0.9.0",
"karma": "^0.13.22",
"karma-browserify": "^5.0.2",
"karma-coverage": "^0.5.5",
"karma-mocha": "^0.2.2",
"karma-mocha-reporter": "^2.0.0",
"karma-phantomjs-launcher": "^1.0.0",
"mocha": "^2.4.5",
"phantomjs-prebuilt": "^2.1.5",
"sinon": "^1.17.3",
"watchify": "^3.7.0"
}
"babel-plugin-transform-object-assign": "^6.5.0",
"babel-plugin-transform-object-rest-spread": "^6.6.5",
"babel-polyfill": "^6.9.0",
"babel-preset-es2015": "^6.5.0",
"babelify": "^7.2.0",
"browserify": "^13.0.0",
"browserify-babel-istanbul": "^0.4.0",
"chai": "^3.5.0",
"codecov.io": "^0.1.6",
"http-server": "^0.9.0",
"istanbul": "^0.4.3",
"karma": "^0.13.22",
"karma-browserify": "^5.0.2",
"karma-coverage": "^0.5.5",
"karma-mocha": "^0.2.2",
"karma-mocha-reporter": "^2.0.0",
"karma-phantomjs-launcher": "^1.0.0",
"mocha": "^2.4.5",
"phantomjs-prebuilt": "^2.1.5",
"sinon": "^1.17.3",
"watchify": "^3.7.0"
},
"dependencies": {
"image-filter-core": "0.0.1"
},
"browserify": {
"transform": [
"babelify"
]
}
}

@@ -25,4 +25,3 @@ ![build status](https://travis-ci.org/canastro/image-filter-threshold.svg?branch=master)

data: IMAGE_DATA,
threshold: 30,
asDataURL: true //if you want data to data transformation you don't need to include this
threshold: 30
});

@@ -53,11 +52,11 @@ ```

```js
var result = imageThreshold({
imageThreshold({
data: IMAGE_DATA
}).then(function (result) {
var image = document.createElement('img');
image.setAttribute('src', result);
var target = document.getElementById('#dummy-target');
target.appendChild(image);
});
var image = document.createElement('img');
image.setAttribute('src', result);
var target = document.getElementById('#dummy-target');
target.appendChild(image);
```

@@ -1,10 +0,6 @@

var imageThreshold = require('../src/index');
import imageThreshold from '../src/index';
function applyResults(selector, src) {
var target;
var image;
target = document.querySelectorAll(selector)[0];
image = document.createElement('img');
const target = document.querySelectorAll(selector)[0];
const image = document.createElement('img');
image.setAttribute('src', src);

@@ -16,29 +12,28 @@ target.appendChild(image);

var canvas;
var context;
var img = new Image;
img.onload = function(){
var canvas = document.createElement('canvas');
const img = new Image;
img.onload = () => {
const canvas = document.createElement('canvas');
canvas.width = img.width;
canvas.height = img.height;
var context = canvas.getContext('2d');
context.drawImage(img,0,0);
const context = canvas.getContext('2d');
context.drawImage(img, 0, 0);
var data = context.getImageData(0, 0, img.width, img.height);
const data = context.getImageData(0, 0, img.width, img.height);
var results1 = imageThreshold({
imageThreshold({
data: data,
threshold: 50,
asDataURL: true //if you want data to data transformation you don't need to include this
threshold: 50
}).then((results) => {
applyResults('#target-1', results);
});
applyResults('#target-1', results1);
var results2 = imageThreshold({
imageThreshold({
data: data,
threshold: 128,
asDataURL: true //if you want data to data transformation you don't need to include this
threshold: 128
}).then((results) => {
applyResults('#target-1', results);
});
applyResults('#target-2', results2);
};
img.src = "dummy.jpg";
}
img.src = 'dummy.jpg';
};

@@ -1,53 +0,41 @@

var utils = require('./utils');
import worker from './worker';
import { apply, getCanvas } from 'image-filter-core';
/**
* @name transform
* @param {object} canvas
* @param {object} context
* @param {object} imageData
* @param {number} threshold
* Iterate over the array applying the threshold transformation
*/
function transform(imageData, threshold) {
var data = imageData.data;
for (var i = 0; i < data.length; i+= 4) {
var r = data[i];
var g = data[i+1];
var b = data[i+2];
var v = (0.2126 * r + 0.7152 * g + 0.0722 * b >= threshold) ? 255 : 0;
data[i] = data[i + 1] = data[i + 2] = v;
}
return imageData;
}
/**
* @name imageThreshold
* @name contrastImage
* @param {object} options
* @param {string} options.data - data of a image extracted from a canvas
* @param {string} options.threshold
* @param {string} options.contrast - contrast value to apply
* @param {string} options.nWorkers - number of workers
* @param {bool} options.asDataURL
* @returns {promise}
*/
module.exports = function imageThreshold(options) {
var result;
var canvas;
var context;
export default function (options) {
if (!options.data || !options.threshold) {
throw new Error('image-filter-threshold:: invalid options provided');
throw new Error('image-filter-brightness:: invalid options provided');
}
canvas = utils.getCanvas(options.data.width, options.data.height);
context = canvas.getContext('2d');
const nWorkers = options.nWorkers || 4;
const params = {
threshold: options.threshold
};
const canvas = getCanvas(options.data.width, options.data.height);
const context = canvas.getContext('2d');
options.data = utils.getPixels(canvas, context, options.data);
// Drawing the source image into the target canvas
context.putImageData(options.data, 0, 0);
result = transform(options.data, options.threshold);
const len = canvas.width * canvas.height * 4;
const segmentLength = len / nWorkers; // This is the length of array sent to the worker
const blockSize = canvas.height / nWorkers; // Height of the picture chunck for every worker
if (options.asDataURL) {
return utils.convertToDataURL(canvas, context, result);
}
return result;
return apply(
worker,
nWorkers,
canvas,
context,
params,
blockSize,
segmentLength
);
}

@@ -1,7 +0,8 @@

var sinon = require('sinon');
var expect = require('chai').expect;
var utils = require('../src/utils');
var imageFilterThreshold = require('../src/index');
import sinon from 'sinon';
import { expect } from 'chai';
import * as utils from 'image-filter-core';
import imageBrightness from '../src/index';
import 'babel-polyfill';
describe('index', function () {
describe('index', () => {
var sandbox;

@@ -11,16 +12,18 @@ var canvas;

beforeEach(function () {
// Create a sandbox for the test
sandbox = sinon.sandbox.create();
});
beforeEach(() => {
// Create a sandbox for the test
sandbox = sinon.sandbox.create();
});
afterEach(function () {
// Restore all the things made through the sandbox
sandbox.restore();
});
afterEach(() => {
// Restore all the things made through the sandbox
sandbox.restore();
});
beforeEach(function () {
beforeEach(() => {
context = {
getImageData: sandbox.stub(),
putImageData: sandbox.stub()
};
context = 'context';
canvas = {

@@ -35,12 +38,11 @@ width: 100,

it('should throw error by missing parameters', function () {
var fn = function () {
imageFilterThreshold({});
it('should throw error by missing parameters', () => {
const fn = () => {
imageBrightness({});
};
expect(fn).to.throw(/image-filter-threshold:: invalid options provided/);
expect(fn).to.throw(/image-filter-brightness:: invalid options provided/);
});
it('should apply threshold transformation and return as imageData', function () {
it.skip('should apply transformation and return as imageData', () => {
var imageData = {

@@ -50,60 +52,13 @@ data: [193, 219, 242, 255]

const expectedData = {
data: [255, 255, 255, 255]
};
// const expectedData = {
// data: [224.34440379022422, 262.88216530631394, 296.9732620320856, 255]
// };
sandbox.stub(utils, 'getPixels').returns(imageData);
var result = imageFilterThreshold({
imageBrightness({
data: imageData,
threshold: 50
brightness: 50
}).then((result) => {
console.log(result);
});
expect(result).to.deep.equal(expectedData);
});
it('should apply threshold transformation for a dark pixel', function () {
var imageData = {
data: [10, 10, 10, 255]
};
const expectedData = {
data: [0, 0, 0, 255]
};
sandbox.stub(utils, 'getPixels').returns(imageData);
var result = imageFilterThreshold({
data: imageData,
threshold: 50
});
expect(result).to.deep.equal(expectedData);
});
it('should apply threshold transformation and return as dataURL', function() {
var imageData = {
data: [193, 219, 242, 255]
};
const expectedData = {
data: [255, 255, 255, 255]
};
const expectedURL = 'imageDataURL';
sandbox.stub(utils, 'getPixels').returns(imageData);
sandbox.stub(utils, 'convertToDataURL').returns('imageDataURL');
var result = imageFilterThreshold({
data: imageData,
threshold: 50,
asDataURL: true
});
expect(utils.convertToDataURL.calledWith(canvas, context, expectedData)).to.equal(true);
expect(result).to.deep.equal(expectedURL);
});
});

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