Adds functionality to the JS Image Object allowing it to compress, resize, crop and watermark images.
Useful for uploading images straight to S3 without the need to resize prior.
####Basic usage
varimage=newImage();image.onload=function(){console.log(this.process());}image.src="path/to/image/on/same/domain.png";Output Array, all ready to be sent to S3:
0: Blob
size: 864521
type: "image/jpeg"1: Blob
size: 68766
type: "image/jpeg"2: Blob
size: 14915
type: "image/jpeg"3: Blob
size: 2923
type: "image/jpeg"
length: 4####With uploaded images
<inputtype="file" id="input" multiple/>document.getElementById("input").addEventListener("change",function(){for(vari=0;i<this.files.length;i++){varfile=this.files[i],imageType=/image.*/;// Check file is an imageif(!file.type.match(imageType))continue;varimage=newImage();image.file=file;varreader=newFileReader();reader.onload=(function(img){// Closure to ensure safe passing of correct Imagereturnfunction(e){img.src=e.target.result;console.log(img.process());};})(image);reader.readAsDataURL(file);}},false);####Options All options can be modified by changing the defaults at Image().defaults prior to processing.
Note: If you wish to change or add a watermark, you should replace the string value with an Image Object
// Global defaultsvardefaults=wm.defaults={className: "watermark",type: "image/jpeg",position: "top-right",padding: 25,opacity: 0.8,watermark: {standard: "img/watermark.png?"+(+(newDate())),highres: "img/watermark-high-res.png?"+(+(newDate()))},sizes: {// width, height, crop, watermark, quality (if defaults.type supports it)large: [1280,768,true,"highres",1],standard: [700,420,true,"standard",0.8],low: [320,200,true,"none",0.8],thumbnail: [128,80,true,"none",0.8]}};