Skip to content

Repository files navigation

Gem MIT License Ruby CI

Tinify API client for Ruby

Ruby client for the Tinify API, used for TinyPNG and TinyJPG. Tinify compresses your images intelligently. Read more at http://tinify.com.

Documentation

Go to the documentation for the Ruby client.

Installation

Install the API client:

gem install tinify

Or add this line to your application's Gemfile:

gem "tinify"

Usage

require "tinify"
Tinify.key = "YOUR_API_KEY"

Tinify.from_file("unoptimized.png").to_file("optimized.png")

Convert to another format with the Tinify::Format constants (WEBP, PNG, JPEG, JPG, AVIF, JXL and ANY):

Tinify.from_file("unoptimized.png")
  .convert(type: Tinify::Format::JXL)
  .to_file("optimized.jxl")

Pass several and the API returns the smallest result:

result = Tinify.from_file("unoptimized.png")
  .convert(type: [Tinify::Format::JXL, Tinify::Format::WEBP])
  .result

result.to_file("optimized.#{result.extension}")

The constants are plain strings, so type: "image/jxl" keeps working.

Running tests

bundle install
rake

Integration tests

bundle install
TINIFY_KEY=$YOUR_API_KEY rake integration

License

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

Releases

Packages

Used by

Contributors

Languages