Yii 2.0: yii2-images

yii2 images module for storing and resizing images

Yii2-images is yii2 module that allows to attach images to any of your models, next you can get images in any sizes, also you can set main image of images set.

Module supports Imagick and GD libraries, you can set up it in module settings.

Take a look https://github.com/CostaRico/yii2-images


Yii2, php 5.4


Usage instance:

$model = Model::findOne(12); //Model must have id
//If an image is first it will be main image for this model
//But if you need set another image as main, use second arg
$model->attachImage('../../image2.png', true);
//get all images
$images = $model->getImages();
foreach($images as $img){
    //retun url to full image
    echo $img->getUrl();
    //return url to proportionally resized image by width
    echo $img->getUrl('300x');
    //return url to proportionally resized image by height
    echo $img->getUrl('x300');
    //return url to resized and cropped (center) image by width and height
    echo $img->getUrl('200x300');
//Returns main model image
$image = $model->getImage();
    //get path to resized image 
    echo $image->getPath('400x300');
    //path to original image
    //will remove this image and all cache files

Total 2 comments

#19630 report it
nooneelse at 2015/10/13 10:24am
This extension is confuse

I think this extension is confuse, Imho just add a module to manipulate images would be better

#18559 report it
ahmed.ismail at 2014/11/17 06:10am
Is there a widget?

Its a good extension but it misses a widget to view images in admin area.

Leave a comment

Please to leave your comment.

Create extension
No downloadable files yet