Detalhes do pacote

tinify

tinify72.7kMIT1.8.1

Node.js client for the Tinify API. Tinify compresses your images intelligently. Read more at https://tinify.com.

tinify, tinypng, tinyjpg, compress

readme (leia-me)

NPM Version NPM License

Tinify API client for Node.js

A lightweight Node.js client for the Tinify API, used for tinypng API and TinyJPG. This library lets you intelligently compress, resize, convert, and store images (AVIF, WebP, JPEG, PNG) with minimal effort. Read more at http://tinify.com.

🚀 Features

  • Compress and optimize images in AVIF, WebP, JPEG, and PNG formats
  • Resize with intelligent cropping
  • Convert between formats
  • Preserve metadata (copyright, GPS, creation time)
  • Upload directly to Amazon S3, Google Cloud Storage, or custom S3/Azure storage

📖 Documentation

Go to the full documentation for the Node.js client.

📦 Installation

Install the API client via NPM:

npm install tinify

Or add this to your package.json:

{
  "dependencies": {
    "tinify": "*"
  }
}

Usage

const tinify = require("tinify");
tinify.key = "YOUR_API_KEY";

// Basic from file system
tinify.fromFile("unoptimized.png").toFile("optimized.png");

// From URL
tinify.fromUrl("https://tinypng.com/images/panda-happy.png")
  .toFile("optimized.png");

// Resize
tinify.fromFile("unoptimized.png").resize({
  method: "cover",
  width: 150,
  height: 100
}).toFile("thumbnail.jpg");

// Convert format
tinify.fromFile("photo.jpg").convert({ type: ["image/webp", "image/png"] })
  .result().extension().then(ext => {
    return tinify.fromFile("photo.jpg").toFile("photo." + ext);
  });

// Preserve metadata
tinify.fromFile("original.jpg")
  .preserve("copyright", "location", "creation")
  .toFile("with-meta.jpg");

// Store to Amazon S3
tinify.fromFile("upload.jpg").store({
  service: "s3",
  aws_access_key_id: "KEY",
  aws_secret_access_key: "SECRET",
  region: "us-west-1",
  path: "bucket-name/images/upload.jpg"
});

Running tests

npm install
npm test

Integration tests

npm install
TINIFY_KEY=$YOUR_API_KEY npm run integration

To test with proxy:

$ docker run --rm -it -v ~/.mitmproxy:/home/mitmproxy/.mitmproxy -p 8080:8080 mitmproxy/mitmproxy mitmproxy  --listen-host 0.0.0.0

$ TINIFY_PROXY=http://172.17.0.3:8080 npm run integration

License

This software is licensed under the MIT License. View the license.

changelog (log de mudanças)

1.8.1

  • Set minimum node engine to v14 in package.json
  • Update examples in README
  • Test the code on node 24

1.8.0

  • Refine convert TypeScript types and add type tests
  • Replace unmaintained proxying-agent with https-proxy-agent
  • remove data/cacert.pem and inline the bundle in a JS file for maximum compatibility

1.7.0

  • Added convert and transform functions
  • Added function to get the file extension

1.6.0

  • Rewrite in TypeScript to provide automatically generated and tested types.
  • Drop support for NodeJS 4.0 and below (end of life).

1.5.0

  • Retry failed requests by default.
  • Drop support for NodeJS 0.12 and below (end of life).

1.4.0

  • Support for HTTP proxies.