PHP Classes

Yii2 PHP Thumbnail Generator: Generate a thumbnail image given the image URL

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-03-01 (7 months ago) RSS 2.0 feedNot enough user ratingsTotal: 21 All time: 11,275 This week: 73Up
Version License PHP version Categories
yii2-thumbnailer 1.0.0Custom (specified...5PHP 5, Graphics, Libraries
Description 

Author

This class can generate a thumbnail image given the image URL.

It provides a class that extends the Yi2 framework Component class to take an image passed by its URL or file name and generates a thumbnail image.

The generated thumbnail image can be stored in a server-side directory with the file name and a path the class returns.

Picture of Gabriel Alejandro López López
  Performance   Level  
Name: Gabriel Alejandro López ... <contact>
Classes: 10 packages by
Country: United States United States
Age: 35
All time rank: 4332551 in United States United States
Week rank: 18 Up4 in United States United States Up
Innovation award
Innovation award
Nominee: 3x

Documentation

Yii2 Thumbnailer

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Yii2 component to generate image thumnails of any size.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist daxslab/yii2-thumbnailer "*"

or add

"daxslab/yii2-thumbnailer": "*"

to the require section of your composer.json file.

Configuration

The basic configuration only requires adding the component to the application:

'components' => [
    //...
    'thumbnailer' => [
        'class' => 'daxslab\thumbnailer\Thumbnailer',
    ],
    //...
]

Besides that a default value is always provided, all the options can be configured.

'components' => [
    //...
    'thumbnailer' => [
        'class' => 'daxslab\thumbnailer\Thumbnailer',
        'defaultWidth' => 500,
        'defaultHeight' => 500,
        'thumbnailsBasePath' => '@webroot/assets/thumbs',
        'thumbnailsBaseUrl' => '@web/assets/thumbs',
        'enableCaching' => true, //defaults to false but is recommended
    ],
    //...
]

Usage

Once the extension is configured, simply use it in your views by:

//Generates thumbnail with default values specified in the configuration
Html::img(Yii::$app->thumbnailer->get($imageUrl));

//Generates a 400px width thumbnail. The height is determined as the width because is not set. 
Html::img(Yii::$app->thumbnailer->get($imageUrl, 400));

//Generates a 400x400 pixels thumbnail and 60% quality 
Html::img(Yii::$app->thumbnailer->get($imageUrl, 400, 400));

//Generates a 400x400 pixels thumbnail and 10% quality
Html::img(Yii::$app->thumbnailer->get($imageUrl, 400, 400, 10));

//Generates a 400x400 pixels thumbnail, 10% quality and not cropping the image
//but inserting it into a box with the specified dimensions.
Html::img(Yii::$app->thumbnailer->get($imageUrl, 400, 400, 10, ManipulatorInterface::THUMBNAIL_INSET));

Proudly made by Daxslab.


  Files folder image Files (5)  
File Role Description
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE.md Lic. License text
Accessible without login Plain text file README.md Doc. Documentation
Plain text file Thumbnailer.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:21
This week:0
All time:11,275
This week:73Up