Skip to content
Projets

À propos

PHP client for the Tinify API.

Design et médias

Comment ces chiffres sont mesurés

Progression mesurée des étoiles

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
Historique en cours

Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.

README.md

Original

MIT License CI_CD Packagist Version Packagist PHP Version Support

Tinify API client for PHP

PHP 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 PHP client.

Installation

Install the API client with Composer. Add this to your composer.json:

{
  "require": {
    "tinify/tinify": "*"
  }
}

Then install with:

composer install

Use autoloading to make the client available in PHP:

require_once("vendor/autoload.php");

Usage

Tinify\setKey("YOUR_API_KEY");
Tinify\fromFile("unoptimized.png")->toFile("optimized.png");

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

Tinify\fromFile("unoptimized.png")
    ->convert(array("type" => Tinify\Format::JXL))
    ->toFile("optimized.jxl");

Pass several and the API returns the smallest result:

$converted = Tinify\fromFile("unoptimized.png")
    ->convert(array("type" => array(Tinify\Format::JXL, Tinify\Format::WEBP)));

$result = $converted->result();
echo $result->mediaType(); // the format the API picked
$result->toFile("optimized");

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

Running tests

composer install
vendor/bin/phpunit

Integration tests

composer install
TINIFY_KEY=$YOUR_API_KEY vendor/bin/phpunit --no-configuration test/integration.php

License

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

Explorer des projets similaires

Chargement…