1.0.9 • Published 2 years ago

image-resizor v1.0.9

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

image-resizor

This package supports resizing and converting images in browsers.

Supported formats: jpg, jpeg, png, heic, heif

How to use

import ImageResizor from 'image-resizor';
new ImageResizor(file, {
  maxWidth: 300,
  maxHeight: 300,
  outputType: 'image/jpeg',
  quality: .8,
})
  .init()
  .then(instance => console.log(instance.toDataURL()))
  .catch(e => console.error(e));

Arguments

new ImageResizor(file[, { ...options }])

Options:

KeyTypeDefaultOptions
maxWidthint2200
maxHeightint2200
scalenumber10 - 1
outputTypestring"image/png""image/png" "image/jpeg"
qualitynumber10 - 1 availabe if the outputType is "image/jpeg"

API

Instance

toDataURL() returns the base64 code.

toBlob() async returns a binary object.

After init() , you can call functions below to modify the options.

setMaxSize(maxWidthAndHeight|maxWidth[, maxHeight])

resize(widthAndHeight|width[, height])

scale(value)

Static Methods

getSupportedTypes() returns an object with file types and MIME types that are supported by this package. e.g.

{
  'png': 'image/png',
  'jpg': 'image/jpeg',
  'jpeg': 'image/jpeg',
  ...
}