PHP code example of vintage / yii2-tinify

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];

use vintage\tinify\UploadedFileS3;

return [
    // ...
    UploadedFileS3::PARAM_KEY_AWS_ACCESS_KEY_ID         => '',
    UploadedFileS3::PARAM_KEY_AWS_SECRET_ACCESS_KEY     => '',
    UploadedFileS3::PARAM_KEY_S3_REGION                 => '',
    UploadedFileS3::PARAM_KEY_S3_BUCKET                 => '',
];

$file = UploadedFile::getInstance($model, 'image')->saveAs('image.jpg');

$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();

'controllerMap' => [
    // ...
    'tinify' => \vintage\tinify\cli\TinifyController::class,
],