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);
}
- [Project page] https://github.com/CostaRico/yii2-images</a>
Is there a widget?
Its a good extension but it misses a widget to view images in admin area.
This extension is confuse
I think this extension is confuse, Imho just add a module to manipulate images would be better
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.