Skip to content

Commit

Permalink
Merge branch 'SoSocio-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
rendro committed Oct 20, 2017
2 parents 0c1b6e2 + 5c57c4c commit f57b482
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# vintageJS
> Add a retro/vintage effect to images using the HTML5 canvas element.

> Add a retro/vintage effect to images using the HTML5 canvas element.
[![npm](https://img.shields.io/npm/v/vintagejs.svg?style=flat-square)]()
[![npm](https://img.shields.io/npm/l/vintagejs.svg?style=flat-square)]()
[![Greenkeeper badge](https://badges.greenkeeper.io/rendro/vintageJS.svg)](https://greenkeeper.io/)

![](header.jpg)

Expand All @@ -13,7 +14,6 @@
$ npm install vintagejs
```


## How to use

`vintagejs` is a function that takes a source (URL, ImageElement or CanvasElement) and an effect (object with all the options) and returns a Promise that resolves to a result object.
Expand Down
12 changes: 11 additions & 1 deletion dist/vintage.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var defaultEffect = {
lighten: 0,
viewfinder: false,
sepia: false,
gray: false,
brightness: 0,
contrast: 0
};
Expand Down Expand Up @@ -120,7 +121,8 @@ var applyEffect = function applyEffect(effect) {
var data = ctx.getImageData(0, 0, width, height);
var id = data.data.slice(0);
var sepia = effect.sepia,
saturation = effect.saturation;
saturation = effect.saturation,
gray = effect.gray;


for (var i = id.length / 4; i >= 0; --i) {
Expand All @@ -139,6 +141,13 @@ var applyEffect = function applyEffect(effect) {
b = _ref3[2];
}

if (gray) {
var _ref4 = [r * 0.21 + g * 0.72 + b * 0.07, r * 0.21 + g * 0.72 + b * 0.07, r * 0.21 + g * 0.72 + b * 0.07];
r = _ref4[0];
g = _ref4[1];
b = _ref4[2];
}

if (saturation < 1) {
var avg = (r + g + b) / 3;
r += (avg - r) * (1 - saturation);
Expand Down Expand Up @@ -280,6 +289,7 @@ var loadImage = exports.loadImage = function loadImage(src) {
img.onload = function () {
return resolve(img);
};
img.crossOrigin = 'anonymous';
img.onerror = function (err) {
return reject(err);
};
Expand Down
Loading

0 comments on commit f57b482

Please sign in to comment.