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);
  })
}
相关文章
|
4月前
|
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
|
5月前
|
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”
200 1
|
7月前
Google Earth Engine(GEE)——ImageCollection.fromImages, argument ‘images‘: Invalid type. Expected type
Google Earth Engine(GEE)——ImageCollection.fromImages, argument ‘images‘: Invalid type. Expected type
61 0
|
Java
image-comparison
image-comparison
107 0
|
计算机视觉
【事件图像】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)
157 0
OSError: image file is truncated (12 bytes not processed) Premature end of JPEG file
OSError: image file is truncated (12 bytes not processed) Premature end of JPEG file
524 0
Only POT texture can be compressed to PVRTC format
在图片压缩格式 报这个Warning的时候,意思是该图片必须要采用2的幂次方大小才能使用该格式。 POT: Power of Two. 采取方式是在advanced里边,把Non Power of 2 设置一下。或者原图采用幂次方大小。

热门文章

最新文章