Permalink
Browse files

comments removed

  • Loading branch information...
nitin42 committed Sep 28, 2017
1 parent 584eff4 commit a86895cc7cb6334bafb7762af584a25cf1c8b8e1
Showing with 1 addition and 116 deletions.
  1. +0 βˆ’2 src/utils/build.js
  2. +0 βˆ’6 src/utils/errorMsg.js
  3. +0 βˆ’7 src/utils/getDimensions.js
  4. +0 βˆ’2 src/utils/modes.js
  5. +1 βˆ’74 src/utils/options.js
  6. +0 βˆ’8 src/utils/propsFactory.js
  7. +0 βˆ’16 src/utils/storage.js
  8. +0 βˆ’1 src/worker.js
View
@@ -1,5 +1,3 @@
// Depends on the Jimp browser build, accessible via cdn
// <script src="https://cdn.rawgit.com/oliver-moran/jimp/v0.2.27/browser/lib/jimp.min.js"></script>
import root from 'window-or-global';
let ROOT = typeof root.Jimp === 'function' && root.Jimp !== undefined ? root.Jimp : undefined;
View
@@ -2,12 +2,6 @@ const noJimpInstance = `Browser build for Jimp not found. Place this in your ind
<script src="https://cdn.rawgit.com/oliver-moran/jimp/v0.2.27/browser/lib/jimp.min.js"></script>
`;
// const imageError = `'No support for web worker and found no browser build for Jimp. Place this in -
// your index.html file - <script src="https://cdn.rawgit.com/oliver-moran/jimp/v0.2.27/browser/lib/jimp.min.js"></script>`;
// const workerInfo =
// 'Web worker not supported so the image will be processed in main thread. This may affect the performance and block the UI.';
const webWorkerInfo =
'For better performance, set disableWebWorker to false. This will keep your UI responsive as the image will be processed in a web worker.';
@@ -1,10 +1,3 @@
/**
* This function returns the height of the image based on the props,
* style attributes or the original dimension values
* @param { object } props Component props
* @param { number } original Original dimensions of the image
* @param { string } attribute Height or Width
*/
let getSize = (props, original, attr) => {
if (props.resize !== undefined) return props.resize[attr];
if (props.contain !== undefined) return props.contain[attr];
View
@@ -1,4 +1,3 @@
// Resize modes
const RESIZE_MODES = {
neighbor: 'RESIZE_NEAREST_NEIGHBOR',
bilinear: 'RESIZE_BILINEAR',
@@ -7,7 +6,6 @@ const RESIZE_MODES = {
bezier: 'RESIZE_BEZIER',
};
// Align modes (contain and cover)
const ALIGN_MODES = {
horizontal_left: 'HORIZONTAL_ALIGN_LEFT',
horizontal_center: 'HORIZONTAL_ALIGN_CENTER',
View
@@ -1,11 +1,5 @@
const { ALIGN_MODES, RESIZE_MODES } = require('./modes');
/**
* Process the image and generate a base64 string
* @param { string } image Image
* @param { object } props Image filter props
* @param { function } ROOT Jimp instance
*/
function processImage(image, props, ROOT) {
const {
resize,
@@ -30,86 +24,40 @@ function processImage(image, props, ROOT) {
posterize,
} = props;
/**
* Get the algorithm from Jimp instance
* @param { string } algorithm Algorithm for resize, contain and cover props
*/
function MODE(algorithm) {
return ROOT[algorithm];
}
/**
* Get the mode from prop
* @param { object } prop filter prop
* @param { array } modes array of modes
*/
function getMode(prop, modes) {
return prop !== undefined ? modes[prop.mode] : null;
}
/**
* Set the mode
* @param { object } prop filter prop
* @param { array } modes array of modes
* @param { number } autoMode
*/
function setMode(prop, modes, autoMode) {
return MODE(getMode(prop, modes)) || autoMode;
}
// Automatically measure the dimension
const AUTOMEASURE = ROOT.AUTO;
/**
* Setter for image attribute
* @param { any } value attribute
* @param { any } fallbackTo fallback value
*/
const setter = (value, fallbackTo) => (value !== undefined ? value : fallbackTo);
/**
* Pass the image
*/
image.__proto__.pass = function(image) {
return image;
};
/**
* Apply filter on the image or pass the image
* @param { boolean } filter fiter value
* @param { object } img Jimp image
* @param { string } fn filter name
*/
function setFilterOrForwardTheImage(filter, img, fn) {
return filter ? img[fn]() : image.pass(img);
}
/**
* Scale the image (contain and cover)
* @param { object } prop prop value
* @param { object } img Jimp image
* @param { string } scaleMode contain or cover
*/
function scaleImageWithoutMode(prop, img, scaleMode) {
return prop !== undefined && Object.keys(prop).length > 0
? img[scaleMode](prop.width, prop.height, setMode(prop, ALIGN_MODES, ROOT.HORIZONTAL_ALIGN_CENTER))
: image.pass(image);
}
/**
* Changes the appearence of the image
* @param { number } prop filter value
* @param { object } img Jimp image
* @param { string } filter filter name
*/
function changeImageAppearence(prop, img, filter) {
return prop !== undefined ? img[filter](prop) : image.pass(img);
}
/**
* Manipulate the colors
* @param { object } props color props
*/
function colorManipulation(props) {
const setConfig = [];
@@ -139,7 +87,6 @@ function processImage(image, props, ROOT) {
return [];
}
// This function resizes the image with given dimensions
image.__proto__.resizeAnImage = function(image, resize) {
return resize !== undefined && Object.keys(resize).length > 0
? image.resize(
@@ -150,110 +97,90 @@ function processImage(image, props, ROOT) {
: image.pass(image);
};
// This function changes the quality of the image
image.__proto__.changeImageQuality = function(image, quality) {
return changeImageAppearence(quality, image, 'quality');
};
// This function applies greyscale
image.__proto__.applyGreyscale = function(image, greyscale) {
return setFilterOrForwardTheImage(greyscale, image, 'greyscale');
};
// This function normalizes the image
image.__proto__.normalizeImage = function(image, normalize) {
return setFilterOrForwardTheImage(normalize, image, 'normalize');
};
// This function inverts the image color
image.__proto__.invertImage = function(image, invert) {
return setFilterOrForwardTheImage(invert, image, 'invert');
};
// This function makes the image opaque
image.__proto__.opaqueImage = function(image, opaque) {
return setFilterOrForwardTheImage(opaque, image, 'opaque');
};
// This function applies sepia filter to the image
image.__proto__.sepiaFilter = function(image, sepia) {
return setFilterOrForwardTheImage(sepia, image, 'sepia');
};
// dither565
image.__proto__.ditherFilter = function(image, dither565) {
return setFilterOrForwardTheImage(dither565, image, 'dither565');
};
// This function scales the image by n levels
image.__proto__.scaleImage = function(image, scale) {
return changeImageAppearence(scale, image, 'scale');
};
// This function scales the image with given dimensions
image.__proto__.scaleToFitImage = function(image, scaleToFit) {
return scaleToFit !== undefined
? image.scaleToFit(setter(scaleToFit.width, AUTOMEASURE), setter(scaleToFit.height, AUTOMEASURE))
: image.pass(image);
};
// This functon flips the image (horizontally or vertically)
image.__proto__.flipImage = function(image, flip) {
return flip !== undefined
? image.flip(setter(flip.horizontal, false), setter(flip.vertical, false))
: image.pass(image);
};
// This function rotates the image by a degree and mode
image.__proto__.rotateImage = function(image, rotate) {
return rotate !== undefined
? image.rotate(setter(rotate.degree, 0), setMode(rotate, RESIZE_MODES, false))
: image.pass(image);
};
// This function changes the brightness of the image
image.__proto__.changeBrightness = function(image, brightness) {
return changeImageAppearence(brightness, image, 'brightness');
};
// This function changes the contrast level of the image
image.__proto__.changeContrast = function(image, contrast) {
return changeImageAppearence(contrast, image, 'contrast');
};
// This function fades the image by a factor
image.__proto__.fadeImage = function(image, fade) {
return changeImageAppearence(fade, image, 'fade');
};
// This function change the level of opacity of the image
image.__proto__.changeOpacity = function(image, opacity) {
return changeImageAppearence(opacity, image, 'opacity');
};
// This function blurs the image by a factor
image.__proto__.blurImage = function(image, blur) {
return changeImageAppearence(blur, image, 'blur');
};
// This function applies a posterization effect (like Prisma ?)
image.__proto__.posterizeImage = function(image, posterize) {
return changeImageAppearence(posterize, image, 'posterize');
};
// Scales the image but some part of an image may be boxed
image.__proto__.containImage = function(image, contain) {
return scaleImageWithoutMode(contain, image, 'contain');
};
// Scales an image but some part of the image may be clipped
image.__proto__.coverImage = function(image, cover) {
return scaleImageWithoutMode(cover, image, 'cover');
};
// Applies the image filter or pass the image to generate base64 (blob) if no filters are applied
return image
.clone() // Don't mutate the original image buffer
.clone()
.resizeAnImage(image, resize)
.changeImageQuality(image, quality)
.applyGreyscale(image, greyscale)
@@ -1,7 +1,3 @@
/**
* Returns an object of image filter props
* @param { object } props Component props
*/
const filterPropsToListen = props => {
const {
resize,
@@ -52,10 +48,6 @@ const filterPropsToListen = props => {
};
};
/**
* Returns the rest of the props of the image component like className, alt
* @param { object } props Component props
*/
const getImageProps = props => {
const {
image,
View
@@ -1,23 +1,7 @@
/**
* Set the item in localStorage
* @param {string} key Key name
* @param { object } value Value
* @param { object } store Store reference
*/
const setItem = (key, value, store) => (store !== null ? store.setItem(key, value) : null);
/**
* Get the item from localStorage
* @param { string } key Key name
* @param { object } store Store reference
*/
const getItem = (key, store) => (store !== null ? store.getItem(key) : null);
/**
* Remove the item from localStorage
* @param { string } key
* @param { object } store
*/
const removeItem = (key, store) => (store !== null ? store.removeItem(key) : null);
export { getItem, removeItem, setItem };
View
@@ -1,6 +1,5 @@
const processImage = require('./utils/options');
// Code below is executed in web worker
module.exports = function worker(self) {
self.onmessage = function(e) {
importScripts('https://cdn.rawgit.com/nitin42/5fef1095f281aa0cdf36ad6e5c460c9a/raw/359af525cb063ac002ebcf39274fb6c7d12e2f3e/jimp.min.js');

0 comments on commit a86895c

Please sign in to comment.