Skip to content

Latest commit

 

History

History
83 lines (60 loc) · 1.78 KB

README.md

File metadata and controls

83 lines (60 loc) · 1.78 KB

Image

Image module for my dockerized Yii2 application.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist acid23m/yii2-image "~1.0"

or add

"acid23m/yii2-image": "~1.0"

to the require section of your composer.json file.

Usage

Once the extension is installed, do next:

  • Storage path is not editable - @root/userdata/images. Add userdata/ to .gitignore.

  • Add module (recommended id is imagetool) in backend/config/main.php and frontend/config/main.php.

'modules' => [
    'imagetool' => [
        'class' => \imagetool\Module::class,
        'controllerNamespace' => 'imagetool\controllers\web',
        //'browser_cache_time' => 60,
        //'etag' => true,
        //'unset_cookie' => true,
    ]
]

Helpers

File

// get full path to image
// output: /var/www/site/app/userdata/images/ad/c1/abc123cde456.jpg
echo imagetool\helpers\File::getPath('abc123cde456.jpg');

// get url to image
// output: https://site.com/image-data/abc123cde456.jpg
echo imagetool\helpers\File::getUrl('abc123cde456.jpg');

// get mime type of image in data-uri format
// output: image/png
echo imagetool\helpers\File::getMimeOfDataUri('data:image/png;base64,iVBORw0KG');

// get extension of image in data-uri format
// output: png
echo imagetool\helpers\File::getExtensionOfDataUri('data:image/png;base64,iVBORw0KG');

// delete image
// unlink abc123cde456.jpg, [email protected] and [email protected]
imagetool\helpers\File::delete('abc123cde456.jpg');

Html

// output: <img />
echo imagetool\helpers\Html::img('abc123cde456.jpg', [
    'class' => 'img-responsive',
    'alt' => 'Company logo'
]);