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

image-filter-sepia

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

image-filter-sepia - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

.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-sepia",
"version": "0.0.3",
"version": "0.0.4",
"description": "Small library to apply a sepia filter 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"
]
}
}

@@ -1,2 +0,2 @@

var imageFilterSepia = require('../src/index');
import imageSepia from '../src/index';

@@ -15,20 +15,26 @@ function applyResults(selector, src) {

window.onload = function () {
const img = new Image;
var img = new Image;
img.onload = function(){
var canvas = document.createElement('canvas');
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 = imageFilterSepia({
data: data,
asDataURL: true
imageSepia({
data: data
}).then((results) => {
applyResults('#target-1', results);
});
applyResults('#target-1', results1);
imageSepia({
data: data
}).then((results) => {
applyResults('#target-2', results);
});
};
img.src = "dummy.jpg";
}
img.src = 'dummy.jpg';
};

@@ -1,36 +0,14 @@

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
*/
function transform(imageData) {
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];
data[i] = (r * 0.393) + (g * 0.769) + (b * 0.189);
data[i + 1] = (r * 0.349) + (g * 0.686) + (b * 0.168);
data[i + 2] = (r * 0.272) + (g * 0.534) + (b * 0.131);
};
return imageData;
}
/**
* @name sepia
* @name contrastImage
* @param {object} options
* @param {string} options.data - data of a image extracted from a canvas
* @param {string} options.contrast - contrast value to apply
* @param {string} options.nWorkers - number of workers
* @param {bool} options.asDataURL
* @returns {promise}
*/
module.exports = function sepia(options) {
var factor;
var result;
var canvas;
var context;
export default function contrastImage(options) {
if (!options.data) {

@@ -40,14 +18,22 @@ throw new Error('image-filter-sepia:: invalid options provided');

canvas = utils.getCanvas(options.data.width, options.data.height);
context = canvas.getContext('2d');
const nWorkers = options.nWorkers || 4;
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);
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,
null,
blockSize,
segmentLength
);
}

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

var sinon = require('sinon');
var expect = require('chai').expect;
var utils = require('../src/utils');
var imageFilterSepia = require('../src/index');
import sinon from 'sinon';
import { expect } from 'chai';
import * as utils from 'image-filter-core';
import imageSepia 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,6 +38,5 @@ width: 100,

it('should throw error by missing parameters', function () {
var fn = function () {
imageFilterSepia({});
it('should throw error by missing parameters', () => {
const fn = () => {
imageSepia({});
};

@@ -45,3 +47,3 @@

it('should apply sepia transformation and return as imageData', function () {
it.skip('should apply transformation and return as imageData', () => {
var imageData = {

@@ -51,37 +53,13 @@ data: [193, 219, 242, 255]

const expectedData = {
data: [289.998, 258.247, 201.144, 255]
};
// const expectedData = {
// data: [224.34440379022422, 262.88216530631394, 296.9732620320856, 255]
// };
sandbox.stub(utils, 'getPixels').returns(imageData);
var result = imageFilterSepia({
data: imageData
});
expect(result).to.deep.equal(expectedData);
});
it('should apply sepia transformation and return as dataURL', function() {
var imageData = {
data: [193, 219, 242, 255]
};
const expectedData = {
data: [289.998, 258.247, 201.144, 255]
};
const expectedURL = 'imageDataURL';
sandbox.stub(utils, 'getPixels').returns(imageData);
sandbox.stub(utils, 'convertToDataURL').returns('imageDataURL');
var result = imageFilterSepia({
imageSepia({
data: imageData,
asDataURL: true
brightness: 50
}).then((result) => {
console.log(result);
});
expect(utils.convertToDataURL.calledWith(canvas, context, expectedData)).to.equal(true);
expect(result).to.deep.equal(expectedURL);
});
});
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