Skip to content

Latest commit

 

History

History
42 lines (33 loc) · 1.53 KB

README.md

File metadata and controls

42 lines (33 loc) · 1.53 KB

image-resize-to-bytes NPM version Build Status Dependency Status

Down-sizing bigger images into the best dimensions that meets the specified bytes limits, this will try to produce a resize that has least lost in image quality, e.g. when uploading the image via APIs that has file size restriction.

It resize images using sharp which supports for all JPEG, PNG, WebP, TIFF, GIF and SVG images.

Installation

$ npm install --save image-resize-to-bytes

Usage

const resizeToBytes = require('image-resize-to-bytes');
const axios = require('axios');
axios
  .get(
    'https://assets.vogue.com/photos/5ce2feec0f6084cdac2394bf/master/pass/00016-BURBERRY-RESORT-2020-LONDON.jpg',
    { responseType: 'arraybuffer' }
  )
  .then(({ data: image }) => {
    console.log(image.byteLength); // 1.05m
    // resize to ~200kb
    resizeToBytes(image, 200000).then(smallImage => {
      console.log(smallImage.byteLength); // 190kb
    });
  });

License

MIT © Garry Yao