Yii 2.0: yii2-images

yii2 images module for storing and resizing images
5 followers

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.

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

Requirements

Yii2, php 5.4

Usage

Usage instance:

$model = Model::findOne(12); //Model must have id
 
//If an image is first it will be main image for this model
$model->attachImage('../../image.png');
 
//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();
 
if($image){
    //get path to resized image 
    echo $image->getPath('400x300');
 
    //path to original image
    $image->getPathToOrigin();
 
    //will remove this image and all cache files
    $model->removeImage($image);
}

Total 1 comment

#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
Downloads
No downloadable files yet