[Extension] Easyimage. Easy Creating And Caching Thumbnails On Real Time.

Hello,

Features:

  • Easy to use

  • Support GD and Imagick

  • Automaticly thumbnails caching

  • Cache sorting to subdirectories

  • Based on Kohana Image Library (3.3)

More: https://github.com/zhdanovartur/yii-easyimage

Thanks to Artur.

It’s very easy to use. I used this in my CDetailView, CJuiDialog, and CGridView, and very easy to plug-in.

Below is just one example:




<?php $this->widget('zii.widgets.grid.CGridView', array(

    'id'=>'tool-grid',

    'dataProvider'=>$model->search(),

    'columns'=>array(

        array(

            'name'=>'tool_picture',

            'type'=>'RAW',          

            'value'=>'$data->tool_picture?Yii::app()->easyImage->thumbOf(Yii::getPathOfAlias("webroot")."/../../home/eshaell/toolpic/".$data->tool_picture,

                array(),

                array(

                    "width"=>"90",

                    "height"=>"60",

                    "onMouseOver"=>"bigImg(this);return false;",

                    "onMouseOut"=>"normalImg(this);return false;",

                )):$data->tool_picture',

        ),

...



I did not use resize in here, is because I want to create mouse over to show larger size picture, which looks like bing image search.

And also to prevent the code broken due to the image file does not exist, I added "file_exists()" check in the "thumbOf" function, if file is not exists, then it will return message, additional change is to added escapeshellcmd to the file name, so make sure it allow white space or other characters in the file name on Linux:




public function thumbOf($file, $params = array(), $htmlOptions = array())

    {

        $file=escapeshellcmd($file);

        if(!file_exists($file))

        {

            return "Image file is not found!";

        }

        else

        {

            return CHtml::image($this->thumbSrcOf($file, $params), isset($htmlOptions['alt']) ? $htmlOptions['alt'] : '', $htmlOptions);

        }

    }



One of the best functions I like is "Automaticly thumbnails caching", this make the page very fast, and also hide my original image files.