lens-filter-sepia
Version:
Small library to apply a sepia transformation to a image
29 lines (23 loc) • 910 B
JavaScript
var lensCore = require('lens-core');
var imageSepia = require('../src/index');
function applyResults(selector, canvas, context, src) {
const target = document.querySelectorAll(selector)[0];
const image = document.createElement('img');
image.setAttribute('src', lensCore.convertImageDataToCanvasURL(src));
target.appendChild(image);
}
window.onload = function() {
const img = new Image();
img.onload = function() {
const canvas = document.createElement('canvas');
canvas.width = img.width;
canvas.height = img.height;
const context = canvas.getContext('2d');
context.drawImage(img, 0, 0);
const data = context.getImageData(0, 0, img.width, img.height);
imageSepia({ data, nWorkers: 4 }).then(function(results) {
applyResults('#target-1', canvas, context, results);
});
};
img.src = 'dummy.jpg';
};