Skip to content

Image module for my dockerized Yii2 application.

License

Notifications You must be signed in to change notification settings

acid23m/yii2-image

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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'
]);

About

Image module for my dockerized Yii2 application.

Resources

License

Stars

Watchers

Forks

Packages

No packages published