Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

imageresizetool

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

imageresizetool

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

  • 1.0.0
  • npm
  • Socket score

Version published
Maintainers
1
Created
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

Package last updated on 09 Aug 2018

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc