imageoptimizerjs
v1.0.0
Published
A lightweight JavaScript tool for optimizing images by resizing and reducing image quality.
Downloads
10
Maintainers
Readme
ImageOptimizerJS
JavaScript Function for Image Optimization
Overview
ImageOptimizerJS
is a lightweight JavaScript function designed to optimize images by resizing them and reducing their quality, helping to decrease overall page size. The tool is especially useful when large images are loaded at smaller dimensions, saving bandwidth and improving page load times.
optimizeImage
Function
The optimizeImage
function takes an image file, maximum width, maximum height, and quality as inputs. It resizes the image while maintaining its aspect ratio and reduces its quality using the HTML5 Canvas API. The function returns a promise that resolves to a base64 data URL of the optimized image.
Function Signature
optimizeImage(file, maxWidth, maxHeight, quality) => Promise<string>