2017 © Pedro Peláez
 

yii2-extension yii2-croppic-widget

Croppic widget Yii2 Framework.

image

gudezi/yii2-croppic-widget

Croppic widget Yii2 Framework.

  • Wednesday, November 23, 2016
  • by gudezi
  • Repository
  • 1 Watchers
  • 1 Stars
  • 30 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 20 % Grown

The README.md

Croppic widget Yii2 Framework

Croppic - Este plugin jQuery para el Recorte., (*1)

  • Github - https://github.com/sconsult/croppic
  • sitio web oficial - http://www.croppic.net/

Ajuste

Es aconsejable instalar la extensión a través de composer., (*2)

Sólo tiene que ejecutar el comando en la consola:, (*3)

php composer.phar require --prefer-dist gudezi/yii2-croppic-widget "*"

o agregar, (*4)

"gudezi/yii2-croppic-widget": "*"

en la sección require de su archivo composer.json., (*5)

el uso de

Una vez que haya instalado la extensión, puede usarlo en su código:, (*6)

En el formulario de la vista agregar:, (*7)

    use gudezi\croppic\Croppic;

    $options = [
        'class' => 'croppic',
        'pathroot' => 'yiiBaseAdvanced/backend/web',
    ];
    $pluginOptions= [
        'uploadUrl' => '../upload-crop/upload',
        'cropUrl' => '../upload-crop/crop',
        'modal' => false,
        'doubleZoomControls' => false,
        'enableMousescroll' => true,
        'loaderHtml' => '<div class="loader bubblingG">
            <span id="bubblingG_1"></span>
            <span id="bubblingG_2"></span>
            <span id="bubblingG_3"></span>
        </div> ',
    ];
    echo $form->field($model, 'urlUpload')->widget(Croppic::className(),
        ['options' => $options,'pluginOptions' => $pluginOptions]); 

Crear un controlador para subir y recortar una imagen

namespace backend\controllers;

use Yii;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use gudezi\croppic\actions\CropAction;
use gudezi\croppic\actions\UploadAction;

class UploadCropController extends Controller
{
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'upload' => ['post'],
                    'crop' => ['post'],
                ],
            ],
        ];
    }

    public function actions()
    {
        return [
            'upload' => [
                'class' => 'gudezi\croppic\actions\UploadAction',
                'tempPath' => '@backend/web/img/temp',
                'tempUrl' => '../img/temp/',
                'validatorOptions' => [
                    'checkExtensionByMimeType' => true,
                    'extensions' => 'jpeg, jpg, png',
                    'maxSize' => 3000000,
                    'tooBig' => 'Ha seleccionado una imagen demasiado grande (máx. 3 MB)',
                ],
            ],
            'crop' => [
                'class' => 'gudezi\croppic\actions\CropAction',
                'path' => '@backend/web/img/user/avatar',
                'url' => '../img/user/avatar/',
                'modelAttribute' => 'urlUpload',
            ],
        ];
    }
}

Y para usar los datos del modelo, (*8)

En el formulario de la vista agregar:, (*9)

    use gudezi\croppic\Croppic;

    $options = [
        'class' => 'croppic',
        'pathroot' => 'yiiBaseAdvanced/backend/web',
    ];
    $pluginOptions= [
        'uploadUrl' => '../upload-crop/upload?id='.$model->id,
        'cropUrl' => '../upload-crop/crop?id='.$model->id,
        'modal' => false,
        'doubleZoomControls' => false,
        'enableMousescroll' => true,
        'loaderHtml' => '<div class="loader bubblingG">
            <span id="bubblingG_1"></span>
            <span id="bubblingG_2"></span>
            <span id="bubblingG_3"></span>
        </div> ',
    ];
    echo $form->field($model, 'urlUpload')->widget(Croppic::className(),
        ['options' => $options,'pluginOptions' => $pluginOptions]); 

Crear un controlador para subir y recortar una imagen

namespace backend\controllers;

use Yii;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use gudezi\croppic\actions\CropAction;
use gudezi\croppic\actions\UploadAction;

use backend\models\Fotos;

class UploadCropController extends Controller
{
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'upload' => ['post','get'],
                    'crop' => ['post'],
                ],
            ],
        ];
    }

    public function actions()
    {
        $id = Yii::$app->request->get('id');
        if($id>0)
            $model = $this->findModel($id);
        else
            $model = new Fotos();

        return [
            'upload' => [
                'class' => 'gudezi\croppic\actions\UploadAction',
                'tempPath' => '@backend/web/img/temp',
                'tempUrl' => '../img/temp/',
                'modelAttribute' => 'urlUpload',
                'model' => $model,
                'validatorOptions' => [
                    'checkExtensionByMimeType' => true,
                    'extensions' => 'jpeg, jpg, png',
                    'maxSize' => 3000000,
                    'tooBig' => 'Ha seleccionado una imagen demasiado grande (máx. 3 MB)',
                ],
            ],
            'crop' => [
                'class' => 'gudezi\croppic\actions\CropAction',
                'path' => '@backend/web/img/user/avatar',
                'url' => '../img/user/avatar/',
                'modelAttribute' => 'urlUpload',
                'model' => $model,
            ],
        ];
    }

    protected function findModel($id)
    {
        if (($model = Fotos::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }    
}

The Versions

23/11 2016

dev-master

9999999-dev https://github.com/gudezi/yii2-croppic-widget

Croppic widget Yii2 Framework.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

extension yii2 widget croppic

23/11 2016

1.0.3

1.0.3.0 https://github.com/gudezi/yii2-croppic-widget

Croppic widget Yii2 Framework.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

extension yii2 widget croppic

22/11 2016

1.0.2

1.0.2.0 https://github.com/gudezi/yii2-croppic-widget

Croppic widget Yii2 Framework.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

extension yii2 widget croppic

21/11 2016

1.0.1

1.0.1.0 https://github.com/gudezi/yii2-croppic-widget

Croppic widget Yii2 Framework.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

extension yii2 widget croppic

20/10 2016

1.0.0

1.0.0.0 https://github.com/gudezi/yii2-croppic-widget

Croppic widget Yii2 Framework.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

extension yii2 widget croppic

17/10 2016

dev-dev

dev-dev https://github.com/gudezi/yii2-croppic

Croppic widget Yii2 Framework.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

extension yii2 widget croppic