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

convert-image

v1.1.3

Published

A small library that utilizes the native image decoding capabilities of web browsers to seamlessly convert images between the webp, avif, jpeg, and png formats.

Downloads

22

Readme

Package Name

Convert-Image is a lightweight npm library that allows you to convert and download images in various formats, directly in the browser. It simplifies the process of converting images and provides an easy-to-use API for developers to integrate into their projects. The library is built using the browser's built-in APIs, so it does not require any external dependencies.

Installation

npm install convert-image

Usage

To convert and download an image, use the convertImage function.

import convertImage from 'convert-image';

convertImage(imageSource, fileName, format)

The function takes three parameters: the image source, the desired file name, and the desired format.

The image source can be a URL or a file input.

The file name is the name of the file that will be downloaded. It should not include the file extension.

The format is the desired image format (jpg, png, webp, avif).

Below are some examples:

For images from a URL

import convertImage from 'convert-image';

const imageSource = 'https://picsum.photos/200/300';
const fileName = 'my-image';
const format = 'webp' as 'jpg' | 'png' | 'webp' | 'avif';

convertImage(imageSource, fileName, format)

For images from a file input

import convertImage from "convert-image";

const fileInput = document.querySelector(".image-input");
const format = "webp" as "jpg" | "png" | "webp" | "avif";
fileInput.addEventListener("change", (event) => onChangeHandler(event));
function onChangeHandler(e: Event): void {
	const target = e.target as HTMLInputElement;
	const files = target.files as FileList;
	const file = files[0];
	const fileName = 'output'
	convertImage(file, fileName, format);
}

<!-- HTML -->
<input class="image-input" type="file" accept="image/png, image/jpeg, image/webp, image/avif"/>

Supported Formats

The convert-image library supports the following image formats: jpg, png, webp, avif.

Troubleshooting

If you encounter any issues while using the convert-image library, consider the following troubleshooting tips:

For SSR (Server-Side Rendering) applications: Because convert-image uses the browser's built-in APIs, it cannot be used server-side. Ensure that the library is only used in the browser. You can use the following code to prevent the library from being used on the server:

if (typeof window !== 'undefined') {
    convertImage(imageSource, fileName, format)
}

Ensure that the image source is valid and accessible. Check that the specified format is supported by the library. Make sure you have proper permissions for downloading files from the browser. If you receive CORS (Cross-Origin Resource Sharing) errors, ensure that the server hosting the image allows requests from your domain. If you encounter any bugs or have feature requests, please report them on this GitHub repository.

Contributing

If you would like to contribute to the development of this library, please open up an issue and/or submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file in this repository for details.

Changelog

1.1.2 - 7 June 2023 - Initial release