image-conversion
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "image-conversion", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A simple and easy-to-use JS image convert tools, which can specify size to compress the image.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -10,3 +10,3 @@ # image-conversion | ||
 | ||
 | ||
@@ -49,2 +49,10 @@ ## Getting started | ||
} | ||
// or use an async function | ||
async function view() { | ||
const file = document.getElementById('demo').files[0]; | ||
console.log(file); | ||
const res = await imageConversion.compressAccurately(file,200) | ||
console.log(res); | ||
} | ||
``` | ||
@@ -51,0 +59,0 @@ |
@@ -306,7 +306,7 @@ /** | ||
const mime = dataURL.split(',')[0].match(/:(.*?);/)[1]; //原始图像图片类型 | ||
// const originalSize = file.size; | ||
// console.log('原始图像尺寸:', originalSize); //原始图像尺寸 | ||
// console.log('目标尺寸:', config.size * 1024); | ||
// console.log('目标尺寸max:', resultSize.max); | ||
// console.log('目标尺寸min:', resultSize.min); | ||
const originalSize = file.size; | ||
console.log('原始图像尺寸:', originalSize); //原始图像尺寸 | ||
console.log('目标尺寸:', config.size * 1024); | ||
console.log('目标尺寸max:', resultSize.max); | ||
console.log('目标尺寸min:', resultSize.min); | ||
const image = await methods.dataURLtoImage(dataURL); | ||
@@ -328,11 +328,11 @@ const canvas = await methods.imagetoCanvas(image, config); | ||
for (let x = 1; x <= 7; x++) { | ||
// console.group(); | ||
// console.log("循环次数:", x); | ||
// console.log("当前图片质量", imageQuality); | ||
console.group(); | ||
console.log("循环次数:", x); | ||
console.log("当前图片质量", imageQuality); | ||
compressDataURL = await methods.canvastoDataURL(canvas, imageQuality); | ||
const CalculationSize = compressDataURL.length * proportion; | ||
// console.log("当前图片尺寸", CalculationSize); | ||
// console.log("当前压缩率", CalculationSize / originalSize); | ||
// console.log("与目标体积偏差", CalculationSize / (config.size * 1024) - 1); | ||
// console.groupEnd(); | ||
console.log("当前图片尺寸", CalculationSize); | ||
console.log("当前压缩率", CalculationSize / originalSize); | ||
console.log("与目标体积偏差", CalculationSize / (config.size * 1024) - 1); | ||
console.groupEnd(); | ||
//如果到循环第七次还没有达到精确度的值,那说明该图片不能达到到此精确度要求 | ||
@@ -360,3 +360,3 @@ //这时候最后一次循环出来的dataURL可能不是最精确的,需要取其周边两个dataURL三者比较来选出最精确的; | ||
const compressFile = await methods.dataURLtoFile(compressDataURL, mime); | ||
// console.log("最终图片大小:", compressFile.size); | ||
console.log("最终图片大小:", compressFile.size); | ||
return compressFile; | ||
@@ -363,0 +363,0 @@ } |
401265
291