tinify-nodejs

tinifyMIT活跃维护

Tinify 官方 Node.js 客户端,调用 TinyPNG/TinyJPG 接口批量压缩 PNG 和 JPG 图片,帮你在构建流程里自动瘦身图片体积。

Node.js client for the Tinify API.

1.8.3发布于 2026-07-07 13:38 UTC459star46fork同步于 2026-11-10 06:02 UTC

怎么上手

从 README 代码块原样提取,可能是其中一种安装方式
npm install tinify
npm install
npm test
npm install
硬件要求按 README 关键词推断
有 Docker 镜像
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

这个项目的说明还在生成中,先参考下面「最近发版」和 README。

最近发版

5 个版本1.8.3
  1. 1.8.3最新正式版2026-07-07 · 2026-07-07 13:38 UTC

    What's Changed

    Full Changelog: https://github.com/tinify/tinify-nodejs/compare/1.8.2...1.8.3

  2. 1.8.22025-09-24 · 2025-09-24 07:37 UTC
    查看更新说明
    • Removed GET with body from result() call and replaced with POST with body to prepare for deprecation of GET with body from the API
  3. 1.8.12025-07-02 · 2025-07-02 09:28 UTC
    查看更新说明

    1.8.1

    • Add support for node 24
    • Require at least node 14
    • Update some README text
  4. 1.8.02025-02-20 · 2025-02-20 12:14 UTC
    查看更新说明

    Various issues resolved and some improvements to typing. Also extended the test suite to NodeJS 23.

    • Refine convert TypeScript types and add type tests #41
    • Replace unmaintained proxying-agent with https-proxy-agent #50
    • remove data/cacert.pem and inline the bundle in a JS file for maximum compatibility #50
  5. 1.7.11.7.1 API transcoding2022-10-03 · 2022-10-03 10:00 UTC
    查看更新说明
    • Add helper for getting the file extension on the result object
    • Add convert method for transcoding between file types
    • Add transform method for changing alpha/transparancy

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    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, JXL, WebP, JPEG, PNG) with minimal effort. Read more at http://tinify.com.

    🚀 Features

    • Compress and optimize images in AVIF, JXL, 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
    const source = tinify.fromFile("panda-sticker.jpg");
    const converted = source.convert({type:["image/webp","image/png"]});
    const extension = converted.result().extension();
    extension.then(ext => {
      converted.toFile("panda-sticker." + ext);
    })
    
    // Convert format using the Format constants
    // (tinify.Format.WEBP, PNG, JPEG, JPG, AVIF, JXL and ANY)
    tinify.fromFile("panda-sticker.jpg")
      .convert({type: tinify.Format.JXL})
      .toFile("panda-sticker.jxl");
    
    // Pass several and the API returns the smallest result
    tinify.fromFile("panda-sticker.jpg")
      .convert({type: [tinify.Format.JXL, tinify.Format.WEBP]})
      .toFile("panda-sticker.min");
    
    // 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.