定制 mauglee/yii2-easyimage 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

mauglee/yii2-easyimage

Composer 安装命令:

composer require mauglee/yii2-easyimage

包简介

Image Component for Yii2

关键字:

README 文档

README

Image Component for Yii2

This extension is based on yii-easyImage

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require mauglee/yii2-easyimage

or add

"mauglee/yii2-easyimage": "@dev"

to the require-dev section of your composer.json file.

Usage

Once the extension is installed, simply modify your application configuration as follows:

return [
    'components' => [
        'easyImage' => [
            'class'         => 'cliff363825\image\EasyImage',
            'driver'        => 'GD',
            'quality'       => 100,
            'cachePath'     => '/easyimage/',
            'cacheTime'     => 2592000,
            'retinaSupport' => true,
            'pixel_ratio'   => [ 2, 3 ], // Device pixels per CSS pixel (retina stuff)
            'basePath'      => '@webroot',
            'baseUrl'       => '@web',
        ]
    ],
];

Parameters

  • string $file required - Image file path
  • string $driver - Driver: GD, Imagick

ThumbOf

You can create a thumbnail directly in the View:

// Create and autocache

Yii::$app->easyImage->thumbOf('/path/to/image.jpg', ['rotate' => 90]);

// or

Yii::$app->easyImage->thumbOf('image.jpg', ['rotate' => 90],  ['class' => 'image']);

// or

Yii::$app->easyImage->thumbOf('image.png', [
    'resize' => ['width' => 100, 'height' => 100],
    'rotate' => ['degrees' => 90],
    'sharpen' => 50,
    'background' => '#ffffff',
    'type' => 'jpg',
    'quality' => 60,
  ]);

Note. This method return Html::img()

Example using different filetypes, diferrent images source path:

// in real situation those filenames are retrieved from DB 
$images = [
    '01.jpg',
    '02.jpg',
    '03.png',
];

foreach ( $images as $image ) {
    $file_path = Yii::getAlias( '@app/data/image/logo/' ) . $image;
    if ( is_file( $file_path ) ) {
        echo Yii::$app->easyImage->thumbOf( $file_path, [
            'resize'  => [ 'width' => 300, 'height' => 300 ],
            'type'    => 'jpg',
            'quality' => '86',
        ] );
    }
}

Parameters

  • string $file required - Image file path
  • array $params - Image manipulation methods
  • array $htmlOptions - options for Html::img()

For full details on usage, see the documentation on authors page. Note: Some differencies may occur, because original version is written for Yii v1

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-02-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固