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

@imraan-hendricks/snap-resize

v0.1.0

Published

SnapResize is a lightweight client-side image resizing NPM package that allows you to easily resize images before uploading them to the server.

Downloads

3

Readme

SnapResize

SnapResize is a lightweight client-side image resizing NPM package that allows you to easily resize images before uploading them to the server. It provides a simple and efficient solution for adjusting image dimensions, aspect ratios, and quality.

Installation

Install SnapResize using npm:

npm install @imraan-hendricks/snap-resize

Usage

Here's an example of how to use SnapResize in your JavaScript/TypeScript code:

import { snapResize } from '@imraan-hendricks/snap-resize';

async function handleFileOnChange(e) {
  const files = e.currentTarget.files;
  if (!files || files.length === 0) return;
  try {
    const file = files[0];
    const options = { aspectRatio: '1:1', height: 400, quality: 0.92 };
    const { original, result } = await snapResize(file, options);
    // `original` contains the details of the original image
    // `result` contains the details of the resized image
  } catch (error) {
    alert(error.message);
  }
}

Benefits of Image Resizing

Resizing images before uploading them to the server offers several benefits:

  • Consistency: By resizing images on the client side, you ensure consistent dimensions and aspect ratios across different devices and platforms. This helps maintain visual integrity and avoids distorted or stretched images.
  • Performance: Uploading large images can impact the performance of your web application or website. By resizing images before uploading, you reduce the file size, leading to faster upload times and improved overall performance.
  • Bandwidth Optimization: Smaller image sizes result in reduced bandwidth usage, making it beneficial for users with limited internet connectivity or mobile data plans. Resizing images helps optimize bandwidth consumption and provides a smoother user experience.
  • Storage Efficiency: Storing and serving large images can consume significant storage space and resources on your server. Resizing images before uploading allows you to store smaller-sized images, optimizing storage efficiency and reducing hosting costs.
  • Improved User Experience: Users often prefer websites or applications that load quickly and provide a seamless experience. By reducing the size of images before uploading, you enhance the user experience by minimizing loading times and improving overall responsiveness.

API

snapResize(originalFile, options, minHeight);

Resizes an image based on the provided options.

  • originalFile: The original image file (type: File).
  • options: An object containing the resizing options:
    • aspectRatio: The desired aspect ratio of the resized image (format: 'width:height').
    • height: The desired height of the resized image.
    • quality (optional): The desired image quality (range: 0 to 1, default: 0.92).
  • minHeight (optional): The minimum height (in pixels) of the image to avoid excessive compression (default: 10).

Returns a Promise that resolves to an object containing the following properties:

  • original: An object containing the details of the original image:
    • base64: The base64-encoded representation of the original image.
    • dimensions: An object containing the width and height of the original image.
    • file: The original image file (type: File).
  • result: An object containing the details of the resized image:
    • base64: The base64-encoded representation of the resized image.
    • dimensions: An object containing the width and height of the resized image.
    • file: The resized image file (type: File).

For more detailed information, advanced usage, and customization options, please refer to the documentation.

Contributing

Contributions are always welcome! If you encounter any issues, have suggestions, or want to contribute improvements, please open an issue or submit a pull request in the Github repository.

Support

If you have any questions, issues, or need assistance, please feel free to reach out to our support team at [email protected]. We are here to help and will get back to you as soon as possible.

License

This project is licensed under the MIT License.