image-contrast
Advanced tools
Comparing version 0.0.2 to 0.0.3
21
index.js
@@ -1,3 +0,2 @@ | ||
function getImageData(context, selector) { | ||
function getImageElement(selector) { | ||
var element = document.querySelectorAll(selector)[0]; | ||
@@ -9,2 +8,7 @@ | ||
return element; | ||
} | ||
function getImageData(context, element) { | ||
if (element.tagName !== 'IMG') { | ||
@@ -57,2 +61,3 @@ throw new Error('image-contrast:: invalid origin'); | ||
* @param {object} options | ||
* @param {string} options.url - image url | ||
* @param {string} options.imageData - data of a image extracted from a canvas | ||
@@ -64,2 +69,3 @@ * @param {string} options.from - dom selector of the original image | ||
module.exports = function contrastImage(options) { | ||
var element; | ||
var data; | ||
@@ -70,10 +76,15 @@ var factor | ||
if (!options || !options.contrast || (!options.imageData && !options.from)) { | ||
if (!options || !options.contrast || (!options.url && !options.imageData && !options.from)) { | ||
throw new Error('image-contrast:: invalid options object'); | ||
} | ||
if (options.imageData) { | ||
if (options.url) { | ||
element = document.createElement('img'); | ||
element.setAttribute('src', options.url); | ||
data = getImageData(context, element); | ||
} else if (options.imageData) { | ||
data = options.imageData; | ||
} else if (options.from) { | ||
data = getImageData(context, options.from); | ||
element = getImageElement(options.from); | ||
data = getImageData(context, element); | ||
} | ||
@@ -80,0 +91,0 @@ |
{ | ||
"name": "image-contrast", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Small library to apply a contrast transformation to a image", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -36,2 +36,4 @@ # image-contrast | ||
```js | ||
var imageContrast = require('image-contrast'); | ||
var canvas = document.createElement('canvas'); | ||
@@ -59,1 +61,12 @@ var context = canvas.getContext('2d'); | ||
``` | ||
### From image url: | ||
```js | ||
var imageContrast = require('image-contrast'); | ||
imageContrast({ | ||
url: "http://lorempixel.com/400/200", | ||
to: '#target-5', | ||
contrast: 30 | ||
}); | ||
``` |
var imageContrast = require('../index'); | ||
window.onload = function () { | ||
//Usage 1: | ||
imageContrast({ | ||
@@ -16,2 +18,3 @@ from: '#original', | ||
//Usage 2: | ||
var canvas = document.createElement('canvas'); | ||
@@ -41,2 +44,14 @@ var context = canvas.getContext('2d'); | ||
//Usage 3: | ||
imageContrast({ | ||
url: "http://lorempixel.com/400/200", | ||
to: '#target-5', | ||
contrast: 30 | ||
}); | ||
imageContrast({ | ||
url: "http://lorempixel.com/400/200", | ||
to: '#target-6', | ||
contrast: 70 | ||
}); | ||
} |
Sorry, the diff of this file is not supported yet
6801
123
71