1. Go to this page and download the library: Download vintage/yii2-tinify 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/ */
vintage / yii2-tinify example snippets
use vintage\tinify\UploadedFile;
$file = UploadedFile::getInstance($model, 'image');
$file->saveMetadata = UploadedFile::METADATA_LOCATION;
// or more items
$file->saveMetadata = [UploadedFile::METADATA_LOCATION, UploadedFile::METADATA_CREATION];
$file = UploadedFile::getInstance($model, 'image')
->setRegion('us-west-1')
->setPath('images-bucket/uploads') // path must be provided without slash in the end
->saveAs('image.jpg');
$file = \vintage\tinify\UploadedFile::getInstance($model, 'image');
$file->resize() // creates \vintage\tinify\components\TinifyResize object
->fit() // resize algorithm, also you can use scale() and cover()
->width(600) // set image width
->height(400) // set image height
->process(); // resize image
$file->saveAs('@webroot/uploads');
(new \vintage\tinify\components\TinifyResize('@webroot/uploads/image.jpg'))
->scale()
->width(600)
->process();