yii2-images yii2 images module for storing and resizing images

  1. Requirements
  2. Usage

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</a>

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);
}

0 0
9 followers
0 downloads
Yii Version: 2.0
License: BSD-2-Clause
Category: Others
Developed by: Costa-Rico
Created on: Jul 22, 2014
Last updated: 10 years ago

Related Extensions