Download the PHP package circulon/yii2-images without Composer
On this page you can find all versions of the php package circulon/yii2-images. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download circulon/yii2-images
More information about circulon/yii2-images
Files in circulon/yii2-images
Package yii2-images
Short Description yii2 images module for storing images
License BSD-3-Clause
Informations about the package yii2-images
yii2-images
Yii2-images is yii2 module that allows attachment of images to any model, you can also retrieve images in any sizes. Additionally you can set the main (default) image of a group of images.
Module supports Imagick and GD libraries, you can set up it in module settings.
Features
- single action which can be attached to any controller offering cleaner urls per controller
- optional output of base64 encoded data for use in tags
- optimised searching of db for image references per action
- customisable id attribute
- Handles UploadedFile classes internally so no need to save uploads first before attaching to model
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist circulon/yii2-images "*"
or add
"circulon/yii2-images": "*"
to the require section of your composer.json
file.
Run the migration
Setup
add the module setup to your app config
'modules' => [
...
'images' => [
'class' => 'circulon\images\Module',
// be sure, that permissions ok
// if you cant avoid permission errors you have to create "images" folder in web root manually and set 777 permissions
'imagesStorePath' => 'images/store', //path to origin images
'imagesCachePath' => 'images/cache', //path to resized copies
'graphicsLibrary' => 'GD', //but really its better to use 'Imagick'
'placeholderPath' => '@webroot/images/placeholder.png', // if you want to get placeholder when image not exists, string will be processed by Yii::getAlias
],
],
optionally add the url route to the UrlManager
NOTE : you may need to add a similar rule to your module/s that have this attached action
'components' => [
...
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
...
'<controller:\w+>/<action:\w+>/<id:\d+>/<ref:[a-z0-9_-]+>' => '<controller>/<action>',
...
],
],
...
]
attach the behavior to your model/s
add the action to the required controllers
Usage
with an img tag
Details
-
Get images
-
Remove image/images
-
Set main/default image
-
Get image sizes
-
Get original image
-
Get raw image content or encoded content
$image = $model->getImage(); $content = $model->getContent(); // output base64 encoded thumbnail with bootstrap3 css echo '<img class="img-responsive img-rounded" src="data:image/png;base64,'.$user->getImage()->getContent('50x50', true).'" alt="">';