1.1.3 • Published 1 year ago

image-resizor v1.1.3

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

image-resizor

Effortlessly convert, resize, and compress images (jpg, png, heic, heif, webp) into optimized png and jpg formats, all within the browser environment.

Demo

https://namti.github.io/image-resizor

Usage

import ImageResizor from 'image-resizor';
<script src="https://cdn.jsdelivr.net/npm/image-resizor/dist/image-resizor.iife.js"></script>
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 }])

file

File | Blob

options

KeyTypeDefaultOptions
maxWidthnumber2000
maxHeightnumber2000
scalenumber10.1~1
outputTypestringimage/png"image/png" | "image/jpeg"
backgroundColorstring#ffffffBackground fill for converting images with alpha channel to "image/jpeg"
qualitynumber0.90.1~1 Available if the outputType is "image/jpeg"

Methods

toDataURL()

Converts the image into a data URL.

instance.toDataURL(): string | undefined

toBlob()

Converts the image into a Blob.

instance.toBlob(): Promise<Blob>

getSupportedTypes()

enum ImageType {
  jpg = 'image/jpeg',
  jpeg = 'image/jpeg',
  png = 'image/png',
  heic = 'image/heic',
  heif = 'image/heif',
  webp = 'image/webp',
}
static getSupportedTypes(): typeof ImageType