프로젝트
GitHub에서 보기
tinify/tinify-nodejs
소개
Tinify API용 Node.js 클라이언트입니다.
디자인 및 미디어What you can do
- 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)
측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalTinify 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.
관련 프로젝트 살펴보기
불러오는 중…