Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nestjs-img-resize

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nestjs-img-resize

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.

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14
increased by1300%
Maintainers
1
Weekly downloads
 
Created
Source

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
PropTypeDescription
autoExifRotatebooleanAllow to automatically rotate the image based on exif metadata, default - false
outTypeImageTypesOutput Image Format, default jpeg
fillAlphastringFill the alpha channel with a specific color, useful when converting a format with an alpha channel to a format without it
ImgResizeConfig

extends ImgConvertConfig

PropTypeDescription
widthnumberResized image width, required
heightnumberResized image height, required
exactbooleanIf 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
allowStretchallowStretchStretch the image if it is smaller than the specified size, only works if exact = false, default false
sizeNamestringSize name, for identify resized result, optional
autoExifRotatebooleanAllow to automatically rotate the image based on exif metadata, default - false
outTypeImageTypesOutput Image Format, default jpeg
fillAlphastringFill 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

Keywords

FAQs

Package last updated on 28 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc