resizer-image

1.0.5 • Public • Published

Resizer-Image

A library to resize images in file or base64.

Demo

Code Sandbox

Installation

npm i resizer-image

Usage

import { resize } from "resizer-image";
const sizes = [
    { w: 0, h: 0 }, // keeps width, keeps height
    { w: 160, h: 0 }, // changes width, keeps height ratio
    { w: 0, h: 90 }, // changes height, keeps width ratio
    { w: 160, h: 90 },
    { w: 320, h: 180 },
    { w: 480, h: 270 },
    { w: 640, h: 360 }
  ]
  
const resizedImages = await resize(input, sizes); //=> [ "blob:http://....","blob:http://...."] 

Params

resize(input, sizes, type='png')
Param Description Example
input a file or base64 src e.target.files[0]
sizes an array of sizes [{ w: 160, h: 90 },{ w: 320, h: 180 }]
type image type png, jpeg, jpg, webp
  • h=0, keep the ratio of height
  • w=0, keep the ratio of width

Sources

CodeSandbox: https://codesandbox.io/s/resizer-image-demo-l65mhh?file=/src/App.js

Github: https://github.com/vnseattle/resizer-image

Happy coding

Dev9x

Package Sidebar

Install

npm i resizer-image

Weekly Downloads

3

Version

1.0.5

License

MIT

Unpacked Size

4.39 kB

Total Files

3

Last publish

Collaborators

  • dev9x