New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

frontend-image-compress

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

frontend-image-compress

compress image-type file in frontend using canvas

latest
Source
npmnpm
Version
3.0.2
Version published
Weekly downloads
28
16.67%
Maintainers
1
Weekly downloads
 
Created
Source

A simple function using canvas to compress image file.

Usage

using cdn

<input  type='file' id='test'/>
<script src="https://unpkg.com/frontend-image-compress@latest/dist/index.min.js"></script>
<script>
  const $file = document.querySelector('#test');
  $file.onchange = async function(e) {
    const file = e.target.files[0];
    window.Compress.compressImageFile(file).then(compressedFile=>{}).catch(err=>{
      alert(err.toString())
    })
  }
</script>

using npm or yarn

  • yarn: yarn add frontend-image-compress
  • npm: npm i frontend-image-compress
import { compressImageFile } from 'frontend-image-compress'

const $file = document.querySelector('#test');
$file.onchange = async function(e) {
  const file = e.target.files[0];
  const compressedFile = await compressImageFile(file)
}

API

when using script tag, you need to use window.Compress.xx, Compress is just a namespace

compressImageFile(file, quality):newFile

nametypedescription
fileFilefrom input[type="file"]
qualitynumberrange: 0~1, default is 0.7(decrease this value if you got console warning)
returnPromise<File>compressed file

Changelog

  • 2020-4-26 3.0.1
    • [breaking] filename changed when using cdn (from frontend-image-compress.min.js to index.min.js)
  • 2019-03-16 3.0.0
  • [breaking] add namespace to methods
  • support commonjs

Keywords

image-compress

FAQs

Package last updated on 26 Apr 2020

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