2017 © Pedro Peláez
 

yii2-extension yii2-imagecache

ImageCache for Yii2

image

iutbay/yii2-imagecache

ImageCache for Yii2

  • Wednesday, March 29, 2017
  • by iutbay
  • Repository
  • 2 Watchers
  • 22 Stars
  • 9,647 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 12 Forks
  • 3 Open issues
  • 3 Versions
  • 7 % Grown

The README.md

ImageCache for Yii2

Like the Image module in Drupal, this extension will resize your images on demand :-). If a thumb doesn't exist, the web server's rewrite rules will pass the request to Yii which in turn hands it off to ImageCache to dynamically generate the file., (*1)

WIP..., (*2)

Features

  • [x] image resize on demand
  • [x] text watermark
  • [ ] image watermark

Installation

The preferred way to install this helper is through composer., (*3)

Either run, (*4)

php composer.phar require "iutbay/yii2-imagecache" "*"

or add, (*5)

"iutbay/yii2-imagecache" : "*"

to the require section of your application's composer.json file., (*6)

Configuration

You should : * Add ThumbAction in one of your controller. * Modify your application configuration : * add imageCache component, * add url rule to handle request to missing thumbs., (*7)

Add ThumbAction

You need to add ThumbAction in one of your controller so that imageCache can handle requests to missing thumbs and create them on demand. You could use site controller :, (*8)

class SiteController extends Controller
{
  ...
  public function actions()
  {
      return [
        ...
        'thumb' => 'iutbay\yii2imagecache\ThumbAction',
        ...
      ];
  }
  ...
}

imageCache component config

You should add imageCache component in your application configuration :, (*9)

$config = [
    'components' => [
      ...
      'imageCache' => [
        'class' => 'iutbay\yii2imagecache\ImageCache',
        'sourcePath' => '@app/web/images',
        'sourceUrl' => '@web/images',
        //'thumbsPath' => '@app/web/thumbs',
        //'thumbsUrl' => '@web/thumbs',
        //'sizes' => [
        //    'thumb' => [150, 150],
        //    'medium' => [300, 300],
        //    'large' => [600, 600],
        //],
      ],
      ...
    ],
];

urlManager config

You should enable pretty urls :, (*10)

http://www.yiiframework.com/doc-2.0/guide-start-installation.html#configuring-web-servers, (*11)

You should modify your urlManager configuration :, (*12)

$config = [
    'components' => [
      ...
      'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'rules' => [
          ...
          'thumbs/<path:.*>' => 'site/thumb',
          ...
        ],
      ],
      ...
    ],
];

How to use

= Yii::$app->imageCache->thumb('@web/images/2014/test.jpg') ?>
// <img src="/your-app/thumbs/2014/test_thumb.jpg" alt="">

= Yii::$app->imageCache->thumb('@web/images/2014/test.jpg', 'medium') ?>
// <img src="/your-app/thumbs/2014/test_medium.jpg" alt="">

= Yii::$app->imageCache->thumb('@web/images/2014/test.jpg', 'medium', ['class'=>'img']) ?>
// <img src="/your-app/thumbs/2014/test_medium.jpg" alt="" class="img">

The Versions

29/03 2017

dev-master

9999999-dev https://github.com/iutbay/yii2-imagecache

ImageCache for Yii2

  Sources   Download

The Requires

 

by Kevin LEVRON

cache yii2 image resize thumb

04/12 2014

0.2

0.2.0.0 https://github.com/iutbay/yii2-imagecache

ImageCache for Yii2

  Sources   Download

The Requires

 

by Kevin LEVRON

cache yii2 image resize thumb

02/12 2014

0.1

0.1.0.0 https://github.com/iutbay/yii2-imagecache

ImageCache for Yii2

  Sources   Download

The Requires

 

by Kevin LEVRON

cache yii2 image resize thumb