Socket
Socket
Sign inDemoInstall

lib-image-conversion

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.11 to 2.1.1

index.d.ts

2

build/conversion.js

@@ -1,1 +0,1 @@

"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault"),_regenerator=_interopRequireDefault(require("@babel/runtime/regenerator")),_asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")),_typeof2=_interopRequireDefault(require("@babel/runtime/helpers/typeof"));!function(e){"object"===("undefined"==typeof exports?"undefined":(0,_typeof2.default)(exports))&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):window.imageConversion=e()}(function(){var e={};function t(e){return["image/png","image/jpeg","image/gif"].some(function(t){return t===e})}return e.urltoImage=function(e){return new Promise(function(t,r){var a=new Image;a.onload=function(){return t(a)},a.onerror=function(){return r(new Error("urltoImage(): Image failed to load, please check the image URL"))},a.src=e})},e.urltoBlob=function(e){return fetch(e).then(function(e){return e.blob()})},e.imagetoCanvas=function(){var e=(0,_asyncToGenerator2.default)(_regenerator.default.mark(function e(t){var r,a,n,u,i,o,c,s=arguments;return _regenerator.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:for(o in r=s.length>1&&void 0!==s[1]?s[1]:{},a=document.createElement("canvas"),n=a.getContext("2d"),r)Object.prototype.hasOwnProperty.call(r,o)&&(r[o]=Number(r[o]));r.scale?(c=r.scale>0&&r.scale<10?r.scale:1,i=t.width*c,u=t.height*c):(i=r.width||r.height*t.width/t.height||t.width,u=r.height||r.width*t.height/t.width||t.height),[5,6,7,8].some(function(e){return e===r.orientation})?(a.height=i,a.width=u):(a.height=u,a.width=i),e.t0=r.orientation,e.next=3===e.t0?9:6===e.t0?12:8===e.t0?15:2===e.t0?18:4===e.t0?22:5===e.t0?27:7===e.t0?32:37;break;case 9:return n.rotate(180*Math.PI/180),n.drawImage(t,-a.width,-a.height,a.width,a.height),e.abrupt("break",38);case 12:return n.rotate(90*Math.PI/180),n.drawImage(t,0,-a.width,a.height,a.width),e.abrupt("break",38);case 15:return n.rotate(270*Math.PI/180),n.drawImage(t,-a.height,0,a.height,a.width),e.abrupt("break",38);case 18:return n.translate(a.width,0),n.scale(-1,1),n.drawImage(t,0,0,a.width,a.height),e.abrupt("break",38);case 22:return n.translate(a.width,0),n.scale(-1,1),n.rotate(180*Math.PI/180),n.drawImage(t,-a.width,-a.height,a.width,a.height),e.abrupt("break",38);case 27:return n.translate(a.width,0),n.scale(-1,1),n.rotate(90*Math.PI/180),n.drawImage(t,0,-a.width,a.height,a.width),e.abrupt("break",38);case 32:return n.translate(a.width,0),n.scale(-1,1),n.rotate(270*Math.PI/180),n.drawImage(t,-a.height,0,a.height,a.width),e.abrupt("break",38);case 37:n.drawImage(t,0,0,a.width,a.height);case 38:return e.abrupt("return",a);case 39:case"end":return e.stop()}},e)}));return function(t){return e.apply(this,arguments)}}(),e.canvastoFile=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"image/jpeg";return new Promise(function(a){return e.toBlob(function(e){return a(e)},r,t)})},e.canvastoDataURL=function(){var e=(0,_asyncToGenerator2.default)(_regenerator.default.mark(function e(r,a,n){return _regenerator.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t(n)||(n="image/jpeg"),e.abrupt("return",r.toDataURL(n,a));case 2:case"end":return e.stop()}},e)}));return function(t,r,a){return e.apply(this,arguments)}}(),e.filetoDataURL=function(e){return new Promise(function(t){var r=new FileReader;r.onloadend=function(e){return t(e.target.result)},r.readAsDataURL(e)})},e.dataURLtoImage=function(e){return new Promise(function(t,r){var a=new Image;a.onload=function(){return t(a)},a.onerror=function(){return r(new Error("dataURLtoImage(): dataURL is illegal"))},a.src=e})},e.dataURLtoFile=function(){var e=(0,_asyncToGenerator2.default)(_regenerator.default.mark(function e(r,a){var n,u,i,o,c;return _regenerator.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:for(n=r.split(","),u=n[0].match(/:(.*?);/)[1],i=atob(n[1]),o=i.length,c=new Uint8Array(o);o--;)c[o]=i.charCodeAt(o);return t(a)&&(u=a),e.abrupt("return",new Blob([c],{type:u}));case 8:case"end":return e.stop()}},e)}));return function(t,r){return e.apply(this,arguments)}}(),e.downloadFile=function(e,t){var r=document.createElement("a");r.href=window.URL.createObjectURL(e),r.download=t||Date.now().toString(36),document.body.appendChild(r);var a=document.createEvent("MouseEvents");a.initEvent("click",!1,!1),r.dispatchEvent(a),document.body.removeChild(r)},e.compress=function(){var r=(0,_asyncToGenerator2.default)(_regenerator.default.mark(function r(a){var n,u,i,o,c,s,l,h,f=arguments;return _regenerator.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(n=f.length>1&&void 0!==f[1]?f[1]:{},a instanceof Blob){r.next=3;break}throw new Error("compress(): First arg must be a Blob object or a File object.");case 3:if("object"!==(0,_typeof2.default)(n)&&(n=Object.assign({quality:n})),n.quality=Number(n.quality),!Number.isNaN(n.quality)){r.next=7;break}return r.abrupt("return",a);case 7:return r.next=9,e.filetoDataURL(a);case 9:return u=r.sent,i=u.split(",")[0].match(/:(.*?);/)[1],o="image/jpeg",t(n.type)&&(o=n.type,i=n.type),r.next=15,e.dataURLtoImage(u);case 15:return c=r.sent,r.next=18,e.imagetoCanvas(c,Object.assign({},n));case 18:return s=r.sent,r.next=21,e.canvastoDataURL(s,n.quality,o);case 21:return l=r.sent,r.next=24,e.dataURLtoFile(l,i);case 24:return h=r.sent,r.abrupt("return",h);case 26:case"end":return r.stop()}},r)}));return function(e){return r.apply(this,arguments)}}(),e.compressAccurately=function(){var r=(0,_asyncToGenerator2.default)(_regenerator.default.mark(function r(a){var n,u,i,o,c,s,l,h,f,d,p,g,b,m,w=arguments;return _regenerator.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(n=w.length>1&&void 0!==w[1]?w[1]:{},a instanceof Blob){r.next=3;break}throw new Error("compressAccurately(): First arg must be a Blob object or a File object.");case 3:if("object"!==(0,_typeof2.default)(n)&&(n=Object.assign({size:n})),n.size=Number(n.size),!Number.isNaN(n.size)){r.next=7;break}return r.abrupt("return",a);case 7:if(!(1024*n.size>a.size)){r.next=9;break}return r.abrupt("return",a);case 9:return n.accuracy=Number(n.accuracy),(!n.accuracy||n.accuracy<.8||n.accuracy>.99)&&(n.accuracy=.95),u={max:n.size*(2-n.accuracy)*1024,accurate:1024*n.size,min:n.size*n.accuracy*1024},r.next=14,e.filetoDataURL(a);case 14:return i=r.sent,o=i.split(",")[0].match(/:(.*?);/)[1],c="image/jpeg",t(n.type)&&(c=n.type,o=n.type),r.next=20,e.dataURLtoImage(i);case 20:return s=r.sent,r.next=23,e.imagetoCanvas(s,Object.assign({},n));case 23:l=r.sent,h=.75,f=.5,p=[null,null],g=1;case 28:if(!(g<=7)){r.next=50;break}return r.next=31,e.canvastoDataURL(l,f,c);case 31:if(d=r.sent,b=d.length*h,7!==g){r.next=36;break}return(u.max<b||u.min>b)&&(d=[d].concat(p).filter(function(e){return e}).sort(function(e,t){return Math.abs(e.length*h-u.accurate)-Math.abs(t.length*h-u.accurate)})[0]),r.abrupt("break",50);case 36:if(!(u.max<b)){r.next=41;break}p[1]=d,f-=Math.pow(.5,g+1),r.next=47;break;case 41:if(!(u.min>b)){r.next=46;break}p[0]=d,f+=Math.pow(.5,g+1),r.next=47;break;case 46:return r.abrupt("break",50);case 47:g++,r.next=28;break;case 50:return r.next=52,e.dataURLtoFile(d,o);case 52:if(!((m=r.sent).size>a.size)){r.next=55;break}return r.abrupt("return",a);case 55:return r.abrupt("return",m);case 56:case"end":return r.stop()}},r)}));return function(e){return r.apply(this,arguments)}}(),e});
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.imageConversion=e():t.imageConversion=e()}(this,(function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";var r;function o(t){return["image/png","image/jpeg","image/gif"].some(e=>e===t)}n.r(e),n.d(e,"canvastoDataURL",(function(){return a})),n.d(e,"canvastoFile",(function(){return c})),n.d(e,"dataURLtoFile",(function(){return s})),n.d(e,"dataURLtoImage",(function(){return l})),n.d(e,"downloadFile",(function(){return d})),n.d(e,"filetoDataURL",(function(){return f})),n.d(e,"imagetoCanvas",(function(){return g})),n.d(e,"urltoBlob",(function(){return w})),n.d(e,"urltoImage",(function(){return m})),n.d(e,"compress",(function(){return p})),n.d(e,"compressAccurately",(function(){return b})),n.d(e,"EImageType",(function(){return r})),function(t){t.PNG="image/png",t.JPEG="image/jpeg",t.GIF="image/gif"}(r||(r={}));var i=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function c(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,c)}u((r=r.apply(t,e||[])).next())}))};function a(t,e=.92,n=r.JPEG){return i(this,void 0,void 0,(function*(){return o(n)||(n=r.JPEG),t.toDataURL(n,e)}))}function c(t,e=.92,n=r.JPEG){return new Promise(r=>t.toBlob(t=>r(t),n,e))}var u=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function c(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,c)}u((r=r.apply(t,e||[])).next())}))};function s(t,e){return u(this,void 0,void 0,(function*(){const n=t.split(",");let r=n[0].match(/:(.*?);/)[1];const i=atob(n[1]);let a=i.length;const c=new Uint8Array(a);for(;a--;)c[a]=i.charCodeAt(a);return o(e)&&(r=e),new Blob([c],{type:r})}))}function l(t){return new Promise((e,n)=>{const r=new Image;r.onload=()=>e(r),r.onerror=()=>n(new Error("dataURLtoImage(): dataURL is illegal")),r.src=t})}function d(t,e){const n=document.createElement("a");n.href=window.URL.createObjectURL(t),n.download=e||Date.now().toString(36),document.body.appendChild(n);const r=document.createEvent("MouseEvents");r.initEvent("click",!1,!1),n.dispatchEvent(r),document.body.removeChild(n)}function f(t){return new Promise(e=>{const n=new FileReader;n.onloadend=t=>e(t.target.result),n.readAsDataURL(t)})}var h=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function c(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,c)}u((r=r.apply(t,e||[])).next())}))};function g(t,e={}){return h(this,void 0,void 0,(function*(){const n=Object.assign({},e),r=document.createElement("canvas"),o=r.getContext("2d");let i,a;for(const t in n)Object.prototype.hasOwnProperty.call(n,t)&&(n[t]=Number(n[t]));if(n.scale){const e=n.scale>0&&n.scale<10?n.scale:1;a=t.width*e,i=t.height*e}else a=n.width||n.height*t.width/t.height||t.width,i=n.height||n.width*t.height/t.width||t.height;switch([5,6,7,8].some(t=>t===n.orientation)?(r.height=a,r.width=i):(r.height=i,r.width=a),n.orientation){case 3:o.rotate(180*Math.PI/180),o.drawImage(t,-r.width,-r.height,r.width,r.height);break;case 6:o.rotate(90*Math.PI/180),o.drawImage(t,0,-r.width,r.height,r.width);break;case 8:o.rotate(270*Math.PI/180),o.drawImage(t,-r.height,0,r.height,r.width);break;case 2:o.translate(r.width,0),o.scale(-1,1),o.drawImage(t,0,0,r.width,r.height);break;case 4:o.translate(r.width,0),o.scale(-1,1),o.rotate(180*Math.PI/180),o.drawImage(t,-r.width,-r.height,r.width,r.height);break;case 5:o.translate(r.width,0),o.scale(-1,1),o.rotate(90*Math.PI/180),o.drawImage(t,0,-r.width,r.height,r.width);break;case 7:o.translate(r.width,0),o.scale(-1,1),o.rotate(270*Math.PI/180),o.drawImage(t,-r.height,0,r.height,r.width);break;default:o.drawImage(t,0,0,r.width,r.height)}return r}))}function w(t){return fetch(t).then(t=>t.blob())}function m(t){return new Promise((e,n)=>{const r=new Image;r.onload=()=>e(r),r.onerror=()=>n(new Error("urltoImage(): Image failed to load, please check the image URL")),r.src=t})}var y=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function c(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,c)}u((r=r.apply(t,e||[])).next())}))};function p(t,e={}){return y(this,void 0,void 0,(function*(){if(!(t instanceof Blob))throw new Error("compress(): First arg must be a Blob object or a File object.");if("object"!=typeof e&&(e=Object.assign({quality:e})),e.quality=Number(e.quality),Number.isNaN(e.quality))return t;const n=yield f(t);let i=n.split(",")[0].match(/:(.*?);/)[1],c=r.JPEG;o(e.type)&&(c=e.type,i=e.type);const u=yield l(n),d=yield g(u,Object.assign({},e)),h=yield a(d,e.quality,c),w=yield s(h,i);return w.size>t.size?t:w}))}function b(t,e={}){return y(this,void 0,void 0,(function*(){if(!(t instanceof Blob))throw new Error("compressAccurately(): First arg must be a Blob object or a File object.");if("object"!=typeof e&&(e=Object.assign({size:e})),e.size=Number(e.size),Number.isNaN(e.size))return t;if(1024*e.size>t.size)return t;e.accuracy=Number(e.accuracy),(!e.accuracy||e.accuracy<.8||e.accuracy>.99)&&(e.accuracy=.95);const n=e.size*(2-e.accuracy)*1024,i=1024*e.size,c=e.size*e.accuracy*1024,u=yield f(t);let d=u.split(",")[0].match(/:(.*?);/)[1],h=r.JPEG;o(e.type)&&(h=e.type,d=e.type);const w=yield l(u),m=yield g(w,Object.assign({},e));let y,p=.5;const b=[null,null];for(let t=1;t<=7;t++){y=yield a(m,p,h);const e=.75*y.length;if(7===t){(n<e||c>e)&&(y=[y,...b].filter(t=>t).sort((t,e)=>Math.abs(.75*t.length-i)-Math.abs(.75*e.length-i))[0]);break}if(n<e)b[1]=y,p-=Math.pow(.5,t+1);else{if(!(c>e))break;b[0]=y,p+=Math.pow(.5,t+1)}}const v=yield s(y,d);return v.size>t.size?t:v}))}}])}));
{
"name": "lib-image-conversion",
"version": "1.1.11",
"version": "2.1.1",
"description": "A simple and easy-to-use JS image convert tools, which can specify size to compress the image.",
"main": "index.js",
"scripts": {
"compress": "gulp",
"lint": "eslint src/conversion.js",
"fix-lint": "eslint --fix src/conversion.js",
"test": "mocha"
},
"author": "anthony.lim",
"files": [
"build",
"src",
"index.d.ts",
"index.js",
"tsconfig.json",
"webpack.config.js"
],
"keywords": [
"image",
"images",
"resize",
"conversion",
"convert",
"compress"
"compress",
"minify",
"jpeg",
"jpg",
"png",
"gif"
],
"git-pre-hooks": {
"pre-commit": "npm run compress"
"license": "MIT",
"scripts": {
"build": "webpack --config webpack.config.js",
"build:test": "webpack --config test/webpack.config.js",
"test": "yarn build:test && http-server . -o /test/unit/"
},
"license": "MIT",
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"src/**/*.ts": "eslint"
},
"devDependencies": {
"@babel/core": "^7.6.4",
"@babel/plugin-transform-runtime": "^7.6.2",
"@babel/preset-env": "^7.6.3",
"eslint": "^5.10.0",
"eslint-config-airbnb-base": "^13.2.0",
"eslint-plugin-import": "^2.18.2",
"git-pre-hooks": "^1.2.0",
"gulp": "^3.9.1",
"gulp-babel": "^8.0.0",
"gulp-uglify-es": "^1.0.4"
},
"dependencies": {
"@babel/runtime": "^7.6.3"
"@types/chai": "^4.2.11",
"@types/mocha": "^7.0.2",
"@typescript-eslint/eslint-plugin": "^2.23.0",
"@typescript-eslint/parser": "^2.23.0",
"chai": "^4.2.0",
"eslint": "^6.8.0",
"http-server": "^0.12.1",
"husky": "^4.2.3",
"lint-staged": "^10.0.8",
"mocha": "^7.1.1",
"ts-loader": "^6.2.1",
"typescript": "^3.8.3",
"webpack": "^4.42.0",
"webpack-cli": "^3.3.11"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc