image-conversion

简介: image-conversion

失之毫厘,差之千里。——佚名

分享一个js图像库:

https://github.com/WangYuLue/image-conversion

Install

npm i image-conversion --save
# or 
yarn add image-conversion

Include the library

in browser:

<script src="https://cdn.jsdelivr.net/gh/WangYuLue/image-conversion/build/conversion.js"></script>

in CommonJS:

const imageConversion = require("image-conversion");

in ES6:

import * as imageConversion from 'image-conversion';

or

import {compress, compressAccurately} from 'image-conversion';

Use examples

<input id="demo" type="file" onchange="view()">
  1. Compress image to 200kb:
function view(){
  const file = document.getElementById('demo').files[0];
  console.log(file);
  imageConversion.compressAccurately(file,200).then(res=>{
    //The res in the promise is a compressed Blob type (which can be treated as a File type) file;
    console.log(res);
  })
}
// 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);
}
  1. Compress images at a quality of 0.9
function view(){
  const file = document.getElementById('demo').files[0];
  console.log(file);
  imageConversion.compress(file,0.9).then(res=>{
    console.log(res);
  })
}
相关文章
|
3月前
|
Python
UserWarning: Palette images with Transparency expressed in bytes should be converted to RGBA images
本文提供了解决PIL库中"Palette images with Transparency"警告的方法,通过将图片转换为'RGB'模式来消除透明通道的问题。
UserWarning: Palette images with Transparency expressed in bytes should be converted to RGBA images
|
4月前
|
Python
已解决:_tkinter.TcLError: couldn’t recognize data in image file “Image/nakamuraan.gif”
已解决:_tkinter.TcLError: couldn’t recognize data in image file “Image/nakamuraan.gif”
161 1
|
6月前
Google Earth Engine(GEE)——ImageCollection.fromImages, argument ‘images‘: Invalid type. Expected type
Google Earth Engine(GEE)——ImageCollection.fromImages, argument ‘images‘: Invalid type. Expected type
54 0
|
6月前
|
算法 光互联 计算机视觉
Locally Adaptive Color Correction for Underwater Image Dehazing and Matching
该文提出了一种新颖的水下图像处理方法,结合颜色转移和局部调整来校正颜色,以应对水下光照和散射造成的图像退化。传统颜色转移方法基于全局参数,不适应水下场景中颜色变化的局部性质。文章中,作者通过融合策略,利用光衰减水平估计来实现局部颜色校正。首先,通过暗通道先验恢复彩色补偿图像,然后估计光衰减图。接着,创建一个合成图像,该图像的统计特性代表高衰减区域,用于颜色转移。最后,通过加权融合初始图像和颜色转移图像,生成最终的颜色校正图像。这种方法旨在提高水下图像的对比度和颜色准确性,特别关注高衰减区域。
84 1
UE Load texture images at runtime Plugin description
UE Load texture images at runtime Plugin description
90 0
|
Python
完美解决 TypeError: Invalid shape (3, 224, 224) for image data
完美解决 TypeError: Invalid shape (3, 224, 224) for image data
919 0
|
编解码 定位技术
Google Earth Engine——Error: Image.clipToBoundsAndScale, argument ‘input‘: Invalid type的错误解决
Google Earth Engine——Error: Image.clipToBoundsAndScale, argument ‘input‘: Invalid type的错误解决
321 0
Google Earth Engine——Error: Image.clipToBoundsAndScale, argument ‘input‘: Invalid type的错误解决
|
计算机视觉
【事件图像】RGB Image conversion to event Image
【事件图像】RGB Image conversion to event Image
【事件图像】RGB Image conversion to event Image
错误及原因:Empty JPEG image (DNL not supported)
错误及原因:Empty JPEG image (DNL not supported)
150 0
[Accessibility] Missing contentDescription attribute on image
[Accessibility] Missing contentDescription attribute on image
181 0
[Accessibility] Missing contentDescription attribute on image