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

@edifice.io/image-resizer

Package Overview
Dependencies
Maintainers
0
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@edifice.io/image-resizer

Edifice Image Resizer

  • 1.7.1-develop.20241126145018
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
154
decreased by-60.61%
Maintainers
0
Weekly downloads
 
Created
Source

Image Resizer

The ImageResizer class provides functionality to resize and compress image files. Below is an overview of its methods and usage.

Methods

changeDimension(height: number, maxHeight: number, width: number, maxWidth: number): { height: number; width: number }

This private static method adjusts the height and width of an image to fit within the specified maximum dimensions while maintaining the aspect ratio.

renameFileNameExtension(filename: string, newExtension: string): string

This private static method changes the file extension of a given filename to the specified new extension.

resizeImage(image: HTMLImageElement, fileName: string, maxWidth: number, maxHeight: number, compressFormat = "jpeg", quality = 80): Promise<File>

This private static method resizes an image to the specified dimensions and compresses it to the specified quality. It returns a promise that resolves to a File object.

resizeImageFile(file: File, maxWidth: number = 1440, maxHeight: number = 1440, quality: number = 80): Promise<File>

This public static method resizes and compresses an image file. It returns a promise that resolves to the resized image file.

Usage

To use the ImageResizer class, you can call the resizeImageFile method with the image file and desired dimensions:

import ImageResizer from "./ImageResizer";

const fileInput = document.getElementById("fileInput") as HTMLInputElement;

fileInput.addEventListener("change", async (event) => {
  const file = (event.target as HTMLInputElement).files?.[0];
  if (file) {
    try {
      const resizedFile = await ImageResizer.resizeImageFile(
        file,
        800,
        600,
        70,
      );
      console.log("Resized file:", resizedFile);
    } catch (error) {
      console.error("Error resizing image:", error);
    }
  }
});

Notes

  • The resizeImageFile method only supports JPEG format for compression.
  • Ensure that the image file is loaded correctly before attempting to resize it.
  • The quality parameter should be a value between 0 and 100.

FAQs

Package last updated on 26 Nov 2024

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