easyimage

Extension for easy creating and caching thumbnails on real time.
24 followers

You don't need to create many types of thumbnails for images in your project. You can create a thumbnail directly in the View. Thumbnail will automatically cached. It's easy!

Features:

  • Easy to use
  • Support GD and Imagick
  • Automaticly thumbnails caching
  • Cache sorting to subdirectories
  • Support Retina displays
  • Based on Kohana Image Library.

Requirements

  • Yii 1.1 or above
  • GD or Imagick

Resources

Note: Latest release and documentation are available from extension github page.

Installing and configuring

Extract the EasyImage folder under protected/extensions

Add the following to your config file components section:

'components'=>array(
    //...
    'easyImage' => array(
        'class' => 'application.extensions.easyimage.EasyImage',
        //'driver' => 'GD',
        //'quality' => 100,
        //'cachePath' => '/assets/easyimage/',
        //'cacheTime' => 2592000,
        //'retinaSupport' => false,
),

and the following to import section:

'import' => array(
    //...
    'ext.easyimage.EasyImage'
),

Usage

InstanceOf

$image = new EasyImage('/path/to/image.jpg');
$image->resize(100, 100);
$image->save('/full/path/to/thumb.jpg');

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', array('rotate' => 90));
 
// or
Yii::app()->easyImage->thumbOf('image.jpg', array('rotate' => 90),  array('class' => 'image'));
 
// or
Yii::app()->easyImage->thumbOf('image.png',
    array(
        'resize' => array('width' => 100, 'height' => 100),
        'rotate' => array('degrees' => 90),
        'sharpen' => 50,
        'background' => '#ffffff',
        'type' => 'jpg',
        'quality' => 60,
    ));

Note. This method return CHtml::image()

Parameters

  • string $file required - Image file path
  • array $params - Image manipulation methods. See Methods
  • array $htmlOptions - options for CHtml::image()

ThumbSrcOf

Yii::app()->easyImage->thumbSrcOf('image.jpg', array('crop' => array('width' => 100, 'height' => 100)));

Note. This method return path to image cached.

Parameters

  • string $file required - Image file path
  • array $params - Image manipulation methods. See Methods

Total 12 comments

#16816 report it
turco_7 at 2014/03/31 08:03am
CGridView ?

Dear all,

Can we use this extension on CGridView? Any idea ?

Regards!

#14919 report it
yasser at 2013/09/21 07:42am
default image

Dear,

very nice extension I used to use Image extension but moving to this....I wanted to ask if it supports default image if the image was not found: example: when trying to resize user profile image if he user doesn't have an image the a default user.png will be returned....

Cheers

#14570 report it
Artur Zhdanov at 2013/08/23 12:26pm
re: How to set it title ?

playdog, your code is correct. Result:

<img title="hola" src="/assets/easyimage/c/c8dc27197f545c9cd85160e3d4764a8d.jpg" alt="">

Maybe you are using the cache for the page?

#14569 report it
playdog at 2013/08/23 12:04pm
How to set it title ?

How to set it title ?

Yii::app()->easyImage->thumbOf($modelNovedades[0]['imagen'],array('resize' => array('height' => 236),'type' => 'jpg','quality' => 60),array('title'=>'hola'))
#14492 report it
Sampa at 2013/08/17 10:38am
Indeed easy

Was indeed very easy to use. I use it to scan my image folder,and then create thumbnails of each image that does not have a thumbnail then display the thumbnail as a link to the full size image. Easy to combine with with any javascript gallery.

<?php
    $imageFolder = "images/portfolio/"; 
    foreach(glob($imageFolder.'*') as $image){ //search our images/portfolio folder for images        
        $filename = str_replace($imageFolder,"",$image); //extract the filename+extension only
        $thumbnail = $imageFolder."thumbnails/".$filename; // thumbnail path
        if(is_file($image)){ //make sure no folder or such is included 
            if(!is_file($thumbnail)){ //if there is no thumbnail create one
                $crop = new EasyImage($imageFolder.$filename); //the image
                $crop->resize(75, 75); //new size
                $crop->save($imageFolder."thumbnails/".$filename); //save to thumbnail
            }
            //echo the thumbnail as a link to the full size image and set title to the filename only
            echo CHtml::link(CHtml::tag('img',array(                
                'src'=>$thumbnail,
                'alt'=>$image,
                )),$image,array('title'=>str_replace(array($imageFolder,'.png','.jpg','.jpeg','.gif'),"",$image)));        
       }
    }?>
#14462 report it
DrMabuse at 2013/08/13 12:49pm
Some problems

Hi

<?php
                        $img = Yii::app()->easyImage->thumbOf($path.$photo->id.'.jpg',
                            array(
                                'resize' => array('width' => 1280, 'height' => null),
                                'type' => 'jpg',
                                'quality' => 100
                            ));
                        $imgNew = str_replace(array('/frontend/www',"<","=","img",'/>','src"','"','alt',' ',"'"),'',$img);
//                        CVarDumper::dump($imgNew);
//                        echo CHtml::image(Yii::app()->createAbsoluteUrl($path.$photo->id.'.jpg'));
                        echo CHtml::image(Yii::app()->createAbsoluteUrl($imgNew));

i wanna save some space on my server then i use your extension. but i have some reasons about your methods. first thing is your thumbOf or your thumbOfSrc doesn't return the right Url. Next thing is i dont understand how to build a retina img without double my images(this step i really doesnt want ).

My Way: My User upload big images like 3000px.... then i cache the size what i need with your extension. My Structure is backend and frontend in other folders. the i save my images in common and build symlink in my Frontend and Backend to my upload Folder then i use your extension to get the sizes what i need but only in Frontend to save Space.

#13260 report it
schmunk at 2013/05/19 08:14am
@leandro: Aliases

Your change request is good, but you can also fix your problem with this workflow.

#13258 report it
leandro at 2013/05/18 10:55am
Thank you

Thank you very much Artur for include this change in a future version!

Can I ask just one more change please? :)

I'm using Yii with Yiiboilerplate. The extensions path alias is different from an standard Yii application.

The EasyImage class imports this:

Yii::import('ext.easyimage.drivers.<class>');

But with Yiiboilerplate, there are several extensions directories for the different applications (for frontend, backend, console and common).

I need change the above lines with:

Yii::import('common.extensions.easyimage.drivers.<class>');

Could the extension alias be configurable too please?

Thank you! Leandro

#13257 report it
Artur Zhdanov at 2013/05/18 08:34am
Absolute path

Leandro, thanks for your comment! I'll do it at nearest time.

#13256 report it
leandro at 2013/05/18 08:17am
Images with absolute path not supported?

Hi, excellent extension.

However, I got a "file name can't be empty" error if I use:

$thumbnail = new EasyImage($absoluteImagePath);

This error is due the EasyImage constructor uses this:

dirname(Yii::app()->basePath) . $file

However, I am using EasyImage from a console command (images are generated asynch) and I need read the images from a different directory and save the thumbs on a different directory.

If I remove "dirname(Yii::app()->basePath)" from EasyImage above line, works like a charm.

Can you add more flexibility regarding paths please?

Thank you, Leandro

#13235 report it
schmunk at 2013/05/16 01:59pm
Looks nice!

+1 for composer support ;)

#13233 report it
le_top at 2013/05/16 01:45pm
Suggestions

Not tested, but will be coming back to this extension ;-).

If not done:

  • Automatic detection of 'driver' (check installed extension and cache the value).
  • Use 'width' and 'height' from the array directly for the resizing [where possible, use parameters provided to regular CHtml::image call];
  • Propose replacement for CHtml::image. Hint: I have my own YHtml class which extends CHtml. I would put a replacement for 'image' in there.

Leave a comment

Please to leave your comment.

Create extension
Downloads
No downloadable files yet