Socket
Socket
Sign inDemoInstall

imageresizetool

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    imageresizetool

简单的易用的js压缩图片方法


Version published
Weekly downloads
3
Maintainers
1
Install size
48.7 kB
Created
Weekly downloads
 

Readme

Source

加载压缩文件依赖

npm install

压缩文件

gulp

七个方法

Alt text

使用示例

var file = document.getElementById('demo').files[0];

imageResizeTool.fileResizetoFile(file,0.6,function(res){
    //回调中的res是一个压缩后的Blob类型(可以当做File类型看待)文件;
    console.log(res);
    //做出你要上传的操作;
})

使用Promise

使用过多的会调函数代码看上去会不优雅,如下:

var canvas = imageResizeTool.imagetoCanvas(img);
imageResizeTool.canvasResizetoFile(canvas,quality,file=>{
    imageResizeTool.filetoDataURL(file,data=>{
        imageResizeTool.dataURLtoImage(data,img=>{
            //做相应的操作
        })
    })
})

这时候可以引入 resize.promise.js 文件,以便使用 Promise 进行链式调用,如下:

imageResizeTool.imagetoCanvas(img)
    .then(canvas => imageResizeTool.canvasResizetoFile(canvas,quality))
    .then(file => imageResizeTool.filetoDataURL(file))
    .then(data => imageResizeTool.dataURLtoImage(data))
    .then(img => {
        //做相应的操作
    })
})

说明文档

王玉略的个人网站

FAQs

Last updated on 10 Aug 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc