Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

image-conversion

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

image-conversion - npm Package Compare versions

Comparing version 1.1.9 to 2.0.0

.DS_Store

2

build/conversion.js

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

"use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};!function(t){"object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):window.imageConversion=t()}(function(){var t={};function e(t){return["image/png","image/jpeg","image/gif"].some(function(e){return e===t})}return t.urltoImage=function(t){return new Promise(function(e,a){var n=new Image;n.onload=function(){return e(n)},n.onerror=function(){return a(new Error("urltoImage(): Image failed to load, please check the image URL"))},n.src=t})},t.urltoBlob=function(t){return fetch(t).then(function(t){return t.blob()})},t.imagetoCanvas=async function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=document.createElement("canvas"),n=a.getContext("2d"),i=void 0,r=void 0;for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(e[o]=Number(e[o]));if(e.scale){var c=e.scale>0&&e.scale<10?e.scale:1;r=t.width*c,i=t.height*c}else r=e.width||e.height*t.width/t.height||t.width,i=e.height||e.width*t.height/t.width||t.height;switch([5,6,7,8].some(function(t){return t===e.orientation})?(a.height=r,a.width=i):(a.height=i,a.width=r),e.orientation){case 3:n.rotate(180*Math.PI/180),n.drawImage(t,-a.width,-a.height,a.width,a.height);break;case 6:n.rotate(90*Math.PI/180),n.drawImage(t,0,-a.width,a.height,a.width);break;case 8:n.rotate(270*Math.PI/180),n.drawImage(t,-a.height,0,a.height,a.width);break;case 2:n.translate(a.width,0),n.scale(-1,1),n.drawImage(t,0,0,a.width,a.height);break;case 4: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);break;case 5: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);break;case 7: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);break;default:n.drawImage(t,0,0,a.width,a.height)}return a},t.canvastoFile=function(t,e){var a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"image/jpeg";return new Promise(function(n){return t.toBlob(function(t){return n(t)},a,e)})},t.canvastoDataURL=async function(t,a,n){return e(n)||(n="image/jpeg"),t.toDataURL(n,a)},t.filetoDataURL=function(t){return new Promise(function(e){var a=new FileReader;a.onloadend=function(t){return e(t.target.result)},a.readAsDataURL(t)})},t.dataURLtoImage=function(t){return new Promise(function(e,a){var n=new Image;n.onload=function(){return e(n)},n.onerror=function(){return a(new Error("dataURLtoImage(): dataURL is illegal"))},n.src=t})},t.dataURLtoFile=async function(t,a){for(var n=t.split(","),i=n[0].match(/:(.*?);/)[1],r=atob(n[1]),o=r.length,c=new Uint8Array(o);o--;)c[o]=r.charCodeAt(o);return e(a)&&(i=a),new Blob([c],{type:i})},t.downloadFile=function(t,e){var a=document.createElement("a");a.href=window.URL.createObjectURL(t),a.download=e||Date.now().toString(36),document.body.appendChild(a);var n=document.createEvent("MouseEvents");n.initEvent("click",!1,!1),a.dispatchEvent(n),document.body.removeChild(a)},t.compress=async function(a){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(a instanceof Blob))throw new Error("compress(): First arg must be a Blob object or a File object.");if("object"!==(void 0===n?"undefined":_typeof(n))&&(n=Object.assign({quality:n})),n.quality=Number(n.quality),Number.isNaN(n.quality))return a;var i=await t.filetoDataURL(a),r=i.split(",")[0].match(/:(.*?);/)[1],o="image/jpeg";e(n.type)&&(o=n.type,r=n.type);var c=await t.dataURLtoImage(i),u=await t.imagetoCanvas(c,Object.assign({},n)),s=await t.canvastoDataURL(u,n.quality,o);return await t.dataURLtoFile(s,r)},t.compressAccurately=async function(a){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(a instanceof Blob))throw new Error("compressAccurately(): First arg must be a Blob object or a File object.");if("object"!==(void 0===n?"undefined":_typeof(n))&&(n=Object.assign({size:n})),n.size=Number(n.size),Number.isNaN(n.size))return a;if(1024*n.size>a.size)return a;n.accuracy=Number(n.accuracy),(!n.accuracy||n.accuracy<.8||n.accuracy>.99)&&(n.accuracy=.95);var i=n.size*(2-n.accuracy)*1024,r=1024*n.size,o=n.size*n.accuracy*1024,c=await t.filetoDataURL(a),u=c.split(",")[0].match(/:(.*?);/)[1],s="image/jpeg";e(n.type)&&(s=n.type,u=n.type);for(var h=await t.dataURLtoImage(c),d=await t.imagetoCanvas(h,Object.assign({},n)),l=.5,f=void 0,g=[null,null],m=1;m<=7;m++){var w=.75*(f=await t.canvastoDataURL(d,l,s)).length;if(7===m){(i<w||o>w)&&(f=[f].concat(g).filter(function(t){return t}).sort(function(t,e){return Math.abs(.75*t.length-r)-Math.abs(.75*e.length-r)})[0]);break}if(i<w)g[1]=f,l-=.5**(m+1);else{if(!(o>w))break;g[0]=f,l+=.5**(m+1)}}var y=await t.dataURLtoFile(f,u);return y.size>a.size?a:y},t});
!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()}(window,(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})),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,n){return i(this,void 0,void 0,(function*(){return o(n)||(n=r.JPEG),t.toDataURL(n,e)}))}function c(t,e,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);return yield s(h,i)}))}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": "image-conversion",
"version": "1.1.9",
"version": "2.0.0",
"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": "wangyulue",
"keywords": [
"image",
"images",
"resize",
"conversion",
"convert",
"compress"
"compress",
"minify",
"jpeg",
"jpg",
"png",
"gif"
],
"git-pre-hooks": {
"pre-commit": "npm run compress",
"pre-push": [
"npm version patch",
"npm publish"
]
"license": "MIT",
"scripts": {
"build": "webpack --config webpack.config.js"
},
"license": "MIT",
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"src/**/*.ts": "eslint"
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-preset-es2015": "^6.24.1",
"eslint": "^5.10.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.14.0",
"git-pre-hooks": "^1.2.0",
"gulp": "^3.9.1",
"gulp-babel": "^7.0.1",
"gulp-uglify-es": "^1.0.4"
},
"dependencies": {}
}
"@typescript-eslint/eslint-plugin": "^2.23.0",
"@typescript-eslint/parser": "^2.23.0",
"eslint": "^6.8.0",
"husky": "^4.2.3",
"lint-staged": "^10.0.8",
"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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc