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

tea-processing

v1.0.3

Published

browser side image processing/compression

Downloads

3

Readme

Tea Processing

Index

Requirements

Features

Setup

Vanilla HTML/JavaScript

  • Download the files (tea-processing.js and webp directory) from GitHub and add them to your project (make sure to maintain the directory structure).

  • Create the main JavaScript file and import the library

import {compress, crop, etc} from "tea-processing.js";
  • Include the main js file as a module.
<script src="main.js" type="module"></script>

ReactJS

  • Install the npm package
npm i tea-processing
  • Import the package in your code
import {compress, crop, etc} from "tea-processing";

API

getBlob(imgFile)

Returns a Promise<Blob> with the image data.

imgFile

Type: File

compress(imgBlob, quality?)

Returns a Promise<Blob> with the compressed image data.

imgBlob

Type: Blob

quality (optional)

Type: number Default: 75

applyRatio(imgBlob, ratio, targetResolution?)

Returns a Promise<Blob> with the image data that's been cropped to right the desired ratio.

imgBlob

Type: Blob

ratio

Type: Float

targetResolution (optional)

Type: object | null { px:number, dimension:string = "width" or "height" } Determines the desired width or height in pixels to scale to.

scale(imgBlob, px, on)

Returns a Promise<Blob> with the image data that's been scaled up or down, to meet the desired resolution on either the width or height, while maintaining the original aspect ratio.

imgBlob

Type: Blob

px

Type: number

on

Type: string = "width" | "height"

crop(imgBlob, cropOptions)

Returns a Promise<Blob> with the image data that's been cropped.

imgBlob

Type: Blob

cropOptions

Type: object { top?:number, right?:number, bottom?:number, left?:number } Example: If you wanted to crop 20px from the top, and 3px from the right, you would pass { top:20, right:3 }

getDimensions(imgBlob)

Returns a Promise<object> { width: number, height: number } with the images width and height in pixels

imgBlob

Type: Blob

getRatio(imgBlob)

Returns a Promise<float> with the images aspect ratio

imgBlob

Type: Blob

Examples

Get Blob

//e.target is referencing a HTML file input
let imgBlob = await getBlob(e.target.files[0])

Compress

//compress to 50% quality
imgBlob = await compress(imgBlob, 50)

Apply Ratio

A target height of 1080 at a ratio of 16/9 will produce an image with a resolution of 1920 by 1080 pixels.

imgBlob = await applyRatio(imgBlob, 16/9, { px:1080, dimension:"height" })

Scale

NOTE: if you're using Apply Ratio, it's more reliable to use the built-in scaling parameter that's provided by Apply Ratio rather than the scale function

imgBlob = await scale(imgBlob, 1080, "height")

Crop

imgBlob = await crop(imgBlob, { left: 40, right: 20 })

Get Dimensions

const dimensions = await getDimensions(imgBlob)

Get Ratio

//container is referencing a HTML div
const ratio = await getRatio(imgBlob)
container.setAttribute("style", `aspect-ratio: ${ratio};`)