首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >image-conversion

image-conversion

作者头像
阿超
发布于 2023-06-23 14:15:29
发布于 2023-06-23 14:15:29
6370
举报
文章被收录于专栏:快乐阿超快乐阿超

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

分享一个js图像库:

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

Include the library

in browser:

代码语言:javascript
复制

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

in CommonJS:

代码语言:javascript
复制
const imageConversion = require("image-conversion");

in ES6:

代码语言:javascript
复制
import * as imageConversion from 'image-conversion';

or

代码语言:javascript
复制
import {compress, compressAccurately} from 'image-conversion';

Use examples

代码语言:javascript
复制
<input id="demo" type="file" onchange="view()">

  1. Compress image to 200kb:
代码语言:javascript
复制
 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
代码语言:javascript
复制
 function view(){
  const file = document.getElementById('demo').files[0];
  console.log(file);
  imageConversion.compress(file,0.9).then(res=>{
    console.log(res);
  })
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-06-07,如有侵权请联系 cloudcommunity@tencent.com 删除
目录
  • Include the library
  • Use examples
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档