@ng-easy/image-optimizer
TypeScript icon, indicating that this package has built-in type declarations

5.1.42 • Public • Published

@ng-easy/image-optimizer

CI npm latest version Downloads CHANGELOG semantic-release renovate

Node library that implements image optimizations for the web. It uses internally the super-fast sharp library.

Usage

import fs from 'fs-extra';
import { getImageOptimizer, ImageOptimizerOptions, ImageOptimizer, ImageCache, FilesystemImageCache } from '@ng-easy/image-optimizer';

// Read the original image from the filesystem
const imageAssetPath = 'image.jpg';
const originalImage: Buffer = await fs.readFile(imageAssetPath);

// Get the optimizer and instantiate a cache (optional)
const imageOptimizer: ImageOptimizer = getImageOptimizer(imageAssetPath, originalImage);
const imageCache: ImageCache = new FilesystemImageCache(path.join(process.cwd(), 'tmp'));

// Run the optimization and get the resulting buffer
const options: ImageOptimizerOptions = { format: 'webp', width: 1080, quality: 70 };
const optimizedImage = await imageOptimizer.optimize(originalImage, imageOptimizationTest.options, imageCache);

Supported file types

  • jpg, webp, heif, avif
  • Pending: png

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @ng-easy/image-optimizer

      Weekly Downloads

      6

      Version

      5.1.42

      License

      MIT

      Unpacked Size

      88.7 kB

      Total Files

      13

      Last publish

      Collaborators

      • samuel.fernandez