2017 © Pedro Peláez
 

yii2-extension yii2-imageupload

Image upload widget with crop for Yii2

image

sergeykoz/yii2-imageupload

Image upload widget with crop for Yii2

  • Sunday, November 27, 2016
  • by serga
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

yii2-imageupload

Installation

The preferred way to install this extension is through composer., (*1)

Either run, (*2)

php composer.phar require --prefer-dist sergeykoz/yii2-imageupload

or add, (*3)

"sergeykoz/yii2-imageupload": "0.3.1",

to the require section of your composer.json., (*4)

Usage

Add upload widget to a form, (*5)

<?php
    use ssoft\imageupload\ImageUpload;    

    echo $form = ActiveForm::begin(['id' => 'image-form', 'options' => ['enctype'=>'multipart/form-data']]);

    // first way
    echo ImageUpload::widget([
        'model' => $photoModel,
        'attribute' => 'photo',
        'parametersAttibute' => 'photo_parameters',
        'addClass' => 'col-sm-8',
        'imageUrl' => Yii::getAlias('@web') . '/files',
        'imagePath' => Yii::getAlias('@webroot') . '/files',
        'placeholder' => 'Photo',
        'size' => ['height' => 300, 'width' => 100],    
        'aspectRatio' => 0.33,
        'disabled' => false
    ]);

    // second way
    echo $form->field($photoModel, 'image')->widget(ImageUpload::className(), [
        'parametersAttibute' => 'image_parameters',
        'imageUrl' => Yii::getAlias('@web') . '/files',
        'imagePath' => Yii::getAlias('@webroot') . '/files',
        'placeholder' => 'Image'
    ]);

    echo ActiveForm::end();
?>

Configure main.php, (*6)

'controllerMap' => [            
    'imageupload' => 'ssoft\imageupload\ImageController',
],

Manage of uploaded images, (*7)

 Yii::getAlias('@webroot') . '/files',
        'imageFile' => $photoModel->photo,
        'parameters' => $photoModel->photo_parameters,
    ]);
    
    // save the image with size 100x300 with name Filename100x300.Ext
    $image->save(
        Yii::getAlias('@webroot') . '/files',
        Image::thumbnailName($photoModel->photo, ['height' => 300, 'width' => 100]), 
        ['height' => 300, 'width' => 100]
    );
    
    // get content of the image png
    echo $image->show('png', ['height' => 600, 'width' => 600]);
?>

The Versions

27/11 2016

dev-master

9999999-dev

Image upload widget with crop for Yii2

  Sources   Download

BSD-3-Clause

The Requires

 

by Sergey Kozin

yii2 upload image crop

27/11 2016

0.0.1

0.0.1.0

Image upload widget with crop for Yii2

  Sources   Download

BSD-3-Clause

The Requires

 

by Sergey Kozin

yii2 upload image crop