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 🙏

© 2025 – Pkg Stats / Ryan Hefner

txx-compress

v0.0.1

Published

image compress library

Downloads

2

Readme

txx-compress

This is a purely browser-side implementation of an image compression library that supports compression of multiple image formats. The current compression library relies on the following third-party libraries.

  • svgo For compressing image/svg+xml format images
  • UPNG.js For compressing image/png format images

The following image formats are supported for compression:

  • image/jpeg
  • image/jpeg
  • image/svg+xml
  • image/png
  • image/webp

For WEBP format compression, the current library depends on whether the browser supports the WEBP image format

Installation

npm install txx-compress

usage

The simplest form is directly through function calls:

// import library
import { compress } from "txx-compress";
// file can be: `File` object | `HTMLImageElement` instance | URL of the image
compress(file);

It can also be called by creating a compression instance, Please note the calling order:

import { TxxCompress } from "txx-compress";
// step1
const txxc = new TxxCompress(file, { quality: 50 });
// step2
await txxc.run();
// step3: Suffixes are automatically added
txxc.download("My Download");

API

Declaration of related types

interface ScaleOption {
  /**
   * Scaling type to ensure that the scaling ratio of width and height is consistent and not distorted
   * 1、Scaling to percentage, width and height at the same time
   * 2、Width scaling to fixed value, height adaptive isometric scaling
   * 3、Height scaling to fixed value, width adaptive isometric scaling
   */
  type?: "percent" | "width" | "height";
  // Value 1-100 when type is percent
  percent?: number;
  // The value when type is width
  width?: number;
  // The value when type is height
  height?: number;
}

interface CompressOption {
  // Compression mass 1-100, the higher the mass the larger the size
  quality?: number;
  scale?: ScaleOption;
}

type ImageSource = Blob | File | HTMLImageElement | string;

Function Call Signatures:

/**
 * Convenient compression functions
 * @param source ImageSource
 * @param option CompressOption
 * @returns
 */
function compress(source: ImageSource, option?: CompressOption): Promise<TxxCompress>;

/**
 * Compress and download, a download box will pop up
 * @param source ImageSource
 * @param option CompressOption
 * @param dlname download file name
 * @returns
 */
function compressAndDownload(source: ImageSource, option?: CompressOption, dlname?: string): Promise<TxxCompress>;

Class Signature:

interface TxxCompress {
  /**
   * Constructors 
   */
  new(source: ImageSource, option?: CompressOption): TxxCompress;
  /**
   * Perform compression
   */
  run(): Promise<void>;
  /**
   * Downloading the compressed file must be called after the run operation
   */
  download(name?: string): void;
}