2017 © Pedro Peláez
 

yii2-extension yii2-imageable

Yii2 extension for handling AR images

image

dlds/yii2-imageable

Yii2 extension for handling AR images

  • Tuesday, February 10, 2015
  • by dlds
  • Repository
  • 1 Watchers
  • 0 Stars
  • 84 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 12 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

ImageAttachment

This extension intended to handle images associated with model., (*1)

Extensions provides user friendly widget, for image upload and removal., (*2)

Yii2 image attachement screenshot, (*3)

Features

  1. Asynchronous image upload
  2. Ability to generate few image versions with different configurations
  3. Drag & Drop

Decencies

  1. Yii2
  2. Twitter bootstrap assets
  3. Imagine library

Installation:

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

Either run, (*5)

php composer.phar require --prefer-dist zxbodya/yii2-image-attachment "*@dev", (*6)

or add, (*7)

"zxbodya/yii2-image-attachment": "*@dev", (*8)

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

Usage

Add ImageAttachmentBehavior to your model, and configure it, create folder for uploaded files., (*10)

public function behaviors()
{
    return [
        TimestampBehavior::className(),
        'coverBehavior' => [
            'class' => ImageAttachmentBehavior::className(),
            // type name for model
            'type' => 'post',
            // image dimmentions for preview in widget 
            'previewHeight' => 200,
            'previewWidth' => 300,
            // extension for images saving
            'extension' => 'jpg',
            // path to location where to save images
            'directory' => Yii::getAlias('@webroot') . '/images/post/cover',
            'url' => Yii::getAlias('@web') . '/images/post/cover',
            // additional image versions
            'versions' => [
                'small' => function ($img) {
                    /** @var ImageInterface $img */
                    return $img
                        ->copy()
                        ->resize($img->getSize()->widen(200));
                },
                'medium' => function ($img) {
                    /** @var ImageInterface $img */
                    $dstSize = $img->getSize();
                    $maxWidth = 800;
                    if ($dstSize->getWidth() > $maxWidth) {
                        $dstSize = $dstSize->widen($maxWidth);
                    }
                    return $img
                        ->copy()
                        ->resize($dstSize);
                },
            ]
        ]
    ];
}

Add ImageAttachmentAction in controller somewhere in your application. Also on this step you can add some security checks for this action., (*11)

public function actions()
{
    return [
        'imgAttachApi' => [
            'class' => ImageAttachmentAction::className(),
            // mappings between type names and model classes (should be the same as in behaviour)
            'types' => [
                'post' => Post::className()
            ]
        ],
    ];
}

Add ImageAttachmentWidget somewhere in you application, for example in editing from., (*12)

echo ImageAttachmentWidget::widget(
    [
        'model' => $model,
        'behaviorName' => 'coverBehavior',
        'apiRoute' => 'test/imgAttachApi',
    ]
)

Done! Now, you can use it in other places in app too:, (*13)

if ($model->getBehavior('coverBehavior')->hasImage()) {
    echo Html::img($model->getBehavior('coverBehavior')->getUrl('medium'));
}

The Versions

10/02 2015

dev-master

9999999-dev

Yii2 extension for handling AR images

  Sources   Download

BSD-3-Clause

The Requires

 

by Jiri Svoboda
by Bogdan Savluk

extension yii2 image

10/02 2015

0.3.1

0.3.1.0

Yii2 extension for handling AR images

  Sources   Download

BSD-3-Clause

The Requires

 

by Jiri Svoboda
by Bogdan Savluk

extension yii2 image

27/01 2015

0.3

0.3.0.0

Yii2 extension for handling AR images

  Sources   Download

BSD-3-Clause

The Requires

 

by Jiri Svoboda
by Bogdan Savluk

extension yii2 image

21/01 2015

0.2

0.2.0.0

Yii2 extension for handling AR images

  Sources   Download

BSD-3-Clause

The Requires

 

by Jiri Svoboda
by Bogdan Savluk

extension yii2 image

21/01 2015

0.1

0.1.0.0

Yii2 extension for handling AR images

  Sources   Download

BSD-3-Clause

The Requires

 

by Jiri Svoboda
by Bogdan Savluk

extension yii2 image