定制 xavier83ar/image-presenter 二次开发

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

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

xavier83ar/image-presenter

Composer 安装命令:

composer require xavier83ar/image-presenter

包简介

A CakePHP plugin for creating thumbnails and image variants on the fly

README 文档

README

Installation

You can install this plugin into your CakePHP application using composer.

The recommended way to install composer packages is:

composer require xavier83ar/image-presenter

Usage

Load the plugin

Plugin::load('ImagePresenter', ['routes' => true]);

Configure your variants...

'ImagePresenter' => [
    'variants' => [
        'thumbnail' => [
            'size' => [350, 250],
            'mode' => ImageInterface::THUMBNAIL_OUTBOUND,
            'filter' => ImageInterface::FILTER_LANCZOS
        ],
        'mini' => [
            'operation' => 'thumbnail',
            'size' => [120, 120],
            'mode' => ImageInterface::THUMBNAIL_INSET,
        ],
        'other' => [
            'operation' => function (ImageInterface $imagine) {
                return $imagine->resize(new Box(400, 300))->rotate(90);
            }
        ],
        'amazing' => [
            'operation' => function (ImageInterface $imagine) {
                return $imagine
                    ->resize(new Box(600, 320))
                    ->effects()->grayscale()->blur(5);
            }
        ],
    ],
]

Any variant which its name starts with "thumbnail" will use thumbnail operation mode. Right now there two operation modes: thumbnail, which sets up a ImageInterface::thumbnail() operation, and closure mode, which allows you to pass a closure which receive an ImageInterface to play with.

This helpers uses imagine/imagine package for image manipulation operations, see https://imagine.readthedocs.org/en/latest/ for more information.

Showing up images

Finally load and use ImageHelper

class AppView extends View
{
    public function initialize()
    {
        $this->loadHelper('ImagePresenter.Image');
    }
}

On your templates

<img src="<?= $this->Image->variant($img, 'thumbnail') ?>" alt="">

ImagePresenter\View\Helper\ImageHelper::variant() method will only check if exists a file for that variant, if it does, then it will return the path to that file relative to webroot, if not, it will return the path to the PresenterController which takes care of generate that variant and serve the file.

This way variants are created only when needed, and only once.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固