1. Go to this page and download the library: Download yasmuru/ys-tinify-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yasmuru / ys-tinify-laravel example snippets
use yasmuru\LaravelTinify\Facades\Tinify;
// Compress from file
$result = Tinify::fromFile('/path/to/image.jpg');
// Compress from buffer/string
$result = Tinify::fromBuffer($imageData);
// Compress from URL
$result = Tinify::fromUrl('https://example.com/image.jpg');
// Save compressed image to file
$result->toFile('/path/to/compressed-image.jpg');
// Get compressed image as buffer
$compressedData = $result->toBuffer();
use yasmuru\LaravelTinify\Facades\Tinify;
// Compress file and upload to S3
$s3Result = Tinify::fileToS3(
'/path/to/image.jpg',
'my-bucket',
'/images/compressed-image.jpg'
);
// Compress buffer and upload to S3
$s3Result = Tinify::bufferToS3(
$imageData,
'my-bucket',
'/images/compressed-image.jpg'
);
// Compress URL and upload to S3
$s3Result = Tinify::urlToS3(
'https://example.com/image.jpg',
'my-bucket',
'/images/compressed-image.jpg'
);
// Get S3 image details
$imageUrl = $s3Result->location();
$imageWidth = $s3Result->width();
$imageHeight = $s3Result->height();
use yasmuru\LaravelTinify\Facades\Tinify;
// Check compression count (free tier has 500 compressions/month).
// compressionCount() is an alias for getCompressionCount().
$count = Tinify::getCompressionCount();
// Set custom API key at runtime
Tinify::setKey('your-custom-api-key');
// Set app identifier
Tinify::setAppIdentifier('My Application');
// Validate the API key. Returns true only if the key is accepted by Tinify;
// returns false for an invalid key or any network/server failure.
$isValid = Tinify::validate();