npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nestjs-img-resize

v1.0.1

Published

NestJS module for simple and flexible image resizing. Uses the [gm](https://www.npmjs.com/package/gm) library and implements a user-friendly interface for resizing and converting images.

Downloads

8

Readme

Description

NestJS module for simple and flexible image resizing. Uses the gm library and implements a user-friendly interface for resizing and converting images.

Features

  • Format support: jpg, jpeg, png, tif, tiff (other formats were not tested)
  • Resize images while maintaining aspect ratio
  • Automatic image rotation by exif metadata
  • Converting images to supported formats
  • Additional settings for resizing images

Installation

Install this library

npm install nestjs-img-resize

The library depends on gm, so the graphicsmagick and imagemagick libraries need to be installed

apt-get install -y graphicsmagick imagemagick

or

brew install imagemagick
brew install graphicsmagick

Usage

Connect the module to your project

@Module({
  imports: [
    NestjsImgResizeModule,
  ],
})
export class AppModule {
}

Inject ImgResizeService into controller or your service

@Injectable()
export class Myservice {
  constructor(protected imgResizeService: ImgResizeService) {
  }
}

Image conversion method

Converting an image to a specific format

convert(image: Buffer, convertConfig: ImgConvertConfig):Promise<Buffer>;

Image resize method

Resize image by configuration

resize(image: Buffer, resizeConfig: ImgResizeConfig): Promise<ImgResizeResponse>;

Image bulk resize method

Resize image by bulk configuration, and the result is images in several sizes.

resizeBulk(image: Buffer, resizeConfig: ImgResizeConfig[]): Promise<ImgResizeResponse[]>

Get image dimension

getImgDimension(buffer: Buffer): Promise<ImgDimension>

Interfaces

ImgConvertConfig

| Prop | Type | Description | |---------------- |------------ |---------------------------------------------------------------------------------------------------------------------------- | | autoExifRotate | boolean | Allow to automatically rotate the image based on exif metadata, default - false | | outType | ImageTypes | Output Image Format, default jpeg | | fillAlpha | string | Fill the alpha channel with a specific color, useful when converting a format with an alpha channel to a format without it |

ImgResizeConfig

extends ImgConvertConfig

| Prop | Type | Description | |-------------- |-------------- |-------------------------------------------------------------------------------------------------------- | | width | number | Resized image width, required | | height | number | Resized image height, required | | exact | boolean | If true then the output image size will have the exact size specified in the configuration, by default false - resizing takes into account the aspect ratio of the image | | allowStretch | allowStretch | Stretch the image if it is smaller than the specified size, only works if exact = false, default false | | sizeName | string | Size name, for identify resized result, optional | | autoExifRotate | boolean | Allow to automatically rotate the image based on exif metadata, default - false | | outType | ImageTypes | Output Image Format, default jpeg | | fillAlpha | string | Fill the alpha channel with a specific color, useful when converting a format with an alpha channel to a format without it |

Benchmark

npm run benchmark

Benchmark results

The results depend on the characteristics of the machine on which the test is performed.
My results on Intel Core i5-10300H CPU @ 2.50GHz × 8, 15,5 GiB, Ubuntu 20.04.2 LTS

v1.0.0

Resize jpg 1920x1080 to 500x281 --> 9.81338447508557 ops/sec | Samples: 49
Resize png 1920x1080 to 500x281 --> 4.821842038356058 ops/sec | Samples: 27
Convert 650x434 png to jpg --> 28.200684305778598 ops/sec | Samples: 68
Convert 650x434 tiff to jpg --> 25.820336860905076 ops/sec | Samples: 45

Tests

npm run test:e2e

License

MIT