Socket
Book a DemoInstallSign in
Socket

ngx-image-compression

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngx-image-compression

A lightweight Angular image compression and conversion library

1.0.3
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

πŸ“¦ ngx-image-compression

A lightweight image compression and conversion library for Angular. Ideal for optimizing large images (like 10MB+) before uploading to S3 or a server. Supports format conversion (e.g., JPG β†’ WebP), resizing, quality tuning, and base64 or Blob output.

πŸš€ Features

  • πŸ”§ Compress images using canvas
  • πŸ“ Resize to desired dimensions
  • 🎯 Convert to different formats (webp, jpeg, png)
  • 🧠 Works with File, Blob, or base64 outputs
  • πŸ“¦ Lightweight and framework-friendly
  • 🟒 Built for Angular 16+ standalone architecture

πŸ“₯ Installation

npm install ngx-image-compression

πŸ› οΈ Usage

import { compressImage } from 'ngx-image-compression';

const result = await compressImage(file, {
  maxWidth: 800,
  maxHeight: 800,
  quality: 0.7,
  format: 'webp',         // optional: 'jpeg', 'png', or 'webp'
  returnType: 'file',     // 'file' | 'base64' | 'blob'
  fileName: 'output'      // only for returnType: 'file'
});

πŸ“˜ Parameters

OptionTypeDefaultDescription
maxWidthnumber800Max width of output image
maxHeightnumber800Max height of output image
qualitynumber0.7Compression quality (0 to 1)
formatstring'webp'Output format: 'webp', 'jpeg', 'png'
returnTypestring'file''file', 'base64', or 'blob'
fileNamestring'output'File name (if returnType is file)

πŸ“¦ Returns

  • If returnType = 'file' β†’ returns a File object
  • If returnType = 'blob' β†’ returns a Blob
  • If returnType = 'base64' β†’ returns a string (base64)

πŸ–ΌοΈ Example with Angular

const result = await compressImage(file, {
  maxWidth: 1024,
  maxHeight: 1024,
  quality: 0.6,
  format: 'jpeg',
  returnType: 'base64'
});
this.previewUrl = result; // Display in 

πŸ“Œ Use Cases

  • Upload large images to AWS S3 with smaller payload
  • Resize user-uploaded profile or gallery images
  • Convert formats (e.g., PNG β†’ WebP) for optimized delivery
  • Reduce load on backend image processing

πŸ”– License

MIT

πŸ” Keywords

angular, image compression, image conversion, webp, optimize image, resize, compress, image, s3 upload, ngx, frontend compression

Keywords

angular

FAQs

Package last updated on 06 Aug 2025

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.