kinglozzer/tinypng

TinyPNG PHP API

Maintainers

👁 kinglozzer

Package info

github.com/kinglozzer/tinypng

Issues

pkg:composer/kinglozzer/tinypng

Statistics

Installs: 95 464

Dependents: 2

Suggesters: 0

Stars: 12

0.1.0 2015-01-30 15:01 UTC

Requires

  • php: >=5.3.3

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

BSD-3-Clause 8ed59147c6b5a6b99ad8b1ae866923a844914508

phpimagecompressionpngjpgtinypngtinyjpg

This package is auto-updated.

Last update: 2026-06-05 01:38:24 UTC


README

👁 Build Status

Provides an easy-to-use API for interacting with TinyPNG's developer API.

Installation

composer require kinglozzer/tinypng:0.1.*

Usage

use Kinglozzer\TinyPng\Compressor;
use Kinglozzer\TinyPng\Exception\AuthorizationException;
use Kinglozzer\TinyPng\Exception\InputException;
use Kinglozzer\TinyPng\Exception\LogicException;

$compressor = new Compressor('<your-tinypng-api-key>');

try {
 $result = $compressor->compress('/path/to/original.png');
 $result = $compressor->compress('<image data>', true); // Compress raw image data
 $result->writeTo('/path/to/compressed.png'); // Write the returned image
 $result->getCompressedFileSize(); // Int size of compressed image, e.g: 104050
 $result->getCompressedFileSize(true); // Human-readable, e.g: '101.61 KB'
 $result->getResponseData(); // array containing JSON-decoded response data
} catch (AuthorizationException $e) {
 // Invalid credentials or requests per month exceeded
} catch (InputException $e) {
 // Not a valid PNG or JPEG
} catch (Exception $e) {
 // Unknown error
}