1. Go to this page and download the library: Download noam148/yii2-image-manager library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
noam148 / yii2-image-manager example snippets
'components' => [
'imagemanager' => [
'class' => 'noam148\imagemanager\components\ImageManagerGetPath',
//set media path (outside the web folder is possible)
'mediaPath' => '/path/where/to/store/images/media/imagemanager',
//path relative web folder. In case of multiple environments (frontend, backend) add more paths
'cachePath' => ['assets/images', '../../frontend/web/assets/images'],
//use filename (seo friendly) for resized images else use a hash
'useFilename' => true,
//show full url (for example in case of a API)
'absoluteUrl' => false,
'databaseComponent' => 'db' // The used database component by the image manager, this defaults to the Yii::$app->db component
],
],
'modules' => [
'imagemanager' => [
'class' => 'noam148\imagemanager\Module',
//set accces rules ()
'canUploadImage' => true,
'canRemoveImage' => function(){
return true;
},
'deleteOriginalAfterEdit' => false, // false: keep original image after edit. true: delete original image after edit
// Set if blameable behavior is used, if it is, callable function can also be used
'setBlameableBehavior' => false,
//add css files (to use in media manage selector iframe)
'cssFiles' => [
'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css',
],
],
],
echo $form->field($model, 'ImageManager_id_avatar')->widget(\noam148\imagemanager\components\ImageManagerInputWidget::className(), [
'aspectRatio' => (16/9), //set the aspect ratio
'cropViewMode' => 1, //crop mode, option info: https://github.com/fengyuanchen/cropper/#viewmode
'showPreview' => true, //false to hide the preview
'showDeletePickedImageConfirm' => false, //on true show warning before detach image
]);
/*
* $ImageManager_id (id that is store in the ImageManager table)
* $width/$height width height of the image
* $thumbnailMode: "outbound", "inset" or "{horz}:{vert}" where {horz} is one from "left", "center", "right" and {vert} is one from "top", "center", "bottom"
*/
\Yii::$app->imagemanager->getImagePath($ImageManager_id, $width, $height,$thumbnailMode)