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

simple-image-compression

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-image-compression

Compress images in the browser

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

simple-image-compression

Compress images in the browser

Usage

  • view example/index.html
<div class="example">
    <div class="title">图片上传压缩例子</div>
    <input type="file" name="file" id="file">
    <div class="box">
        压缩前大小(b): <span id="prev" style="margin-right: 40px"></span>
        压缩后大小(b): <span id="next"></span>
    </div>
</div>
 import compress from simple-image-compression
  const file = document.getElementById('file');
  file.addEventListener('change', async () => {
      const prev = document.getElementById('prev')
      const next = document.getElementById('next')
      prev.innerHTML = ""
      next.innerHTML = ""
      const f = file.files[0]
      const fileSize = f.size / 1024 / 1024;
      prev.innerHTML = f.size
      const quality = 1 / (Math.ceil(fileSize) + 4);
      const compressImageFile = await compress(f, quality)
      next.innerHTML = compressImageFile.size
      file.value = ""
  })

Keywords

FAQs

Package last updated on 26 Sep 2022

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