assayer-pro/yii2-easy-thumbnail-image-helper 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

assayer-pro/yii2-easy-thumbnail-image-helper

Composer 安装命令:

composer require assayer-pro/yii2-easy-thumbnail-image-helper

包简介

Yii2 helper for creating and caching thumbnails on real time

README 文档

README

Yii2 helper for creating and caching thumbnails on real time.

Installation

The preferred way to install this extension is through composer.

  • Either run
php composer.phar require "assayer-pro/yii2-easy-thumbnail-image-helper" "*"

or add

"assayer-pro/yii2-easy-thumbnail-image-helper" : "*"

to the require section of your application's composer.json file.

  • Add a new component in components section of your application's configuration file (optional), for example:
'components' => [
    'thumbnail' => [
        'class' => 'assayerpro\thumbnail\EasyThumbnailImage',
        'cacheAlias' => 'assets/gallery_thumbnails',
        'quality' => 90,
    ],
],

It is necessary if you want to set global helper's settings for the application.

Usage

For example:

use assayerpro\thumbnail\EasyThumbnailImage;

echo Yii::$app->thumbnail->thumbnailImg(
    $model->pictureFile,
    50,
    50,
    EasyThumbnailImage::THUMBNAIL_OUTBOUND,
    ['alt' => $model->pictureName]
);

or

use assayerpro\thumbnail\EasyThumbnailImage;

echo Yii::$app->thumbnail->thumbnailImg(
    'http://...',
    50,
    50,
    EasyThumbnailImage::THUMBNAIL_OUTBOUND,
);

If one of thumbnail dimensions is set to null, another one is calculated automatically based on aspect ratio of original image. Note that calculated thumbnail dimension may vary depending on the source image in this case.

use assayerpro\thumbnail\EasyThumbnailImage;

echo Yii::$app->thumbnail->thumbnailImg(
    $model->pictureFile,
    50,
    null
);

If both dimensions are specified, resulting thumbnail would be exactly the width and height specified. How it's achieved depends on the mode.

For other functions please see the source code.

If you want to handle errors that appear while converting to thumbnail by yourself, please make your own class and inherit it from EasyThumbnailImage. In your class replace only protected method errorHandler. For example

class ThumbHelper extends \assayerpro\thumbnail\EasyThumbnailImage
{

    protected static function errorHandler($error, $filename)
    {
        if ($error instanceof \assayerpro\thumbnail\FileNotFoundException) {
            return \yii\helpers\Html::img('@web/images/notfound.png');
        } else {
            $filename = basename($filename);
            return \yii\helpers\Html::a($filename,"@web/files/$filename");
        }
    }
}

统计信息

  • 总下载量: 34
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 16
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-03-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固