All Projects → zxbodya → Yii2 Image Attachment

zxbodya / Yii2 Image Attachment

This extension intended to handle images associated with model.

Projects that are alternatives of or similar to Yii2 Image Attachment

Yii2 Selectize
selectize.js wrapper for yii2.
Stars: ✭ 18 (-48.57%)
Mutual labels:  yii2, yii2-extension
Yii2 User
[ABANDONED] Flexible user registration and authentication module for Yii2
Stars: ✭ 946 (+2602.86%)
Mutual labels:  yii2, yii2-extension
yii2-blog
Simple, configurable blog module for Yii2 (post, comment, nested category, tags). + frontend, backend. + SEO! (Opengraph, Schema.org) ~~~COMING SOON V2.0~~~ Please STAR this repo
Stars: ✭ 79 (+125.71%)
Mutual labels:  yii2, yii2-extension
yii2-firebird
Firebird connector for Yii2 framework
Stars: ✭ 23 (-34.29%)
Mutual labels:  yii2, yii2-extension
Yii2 Elfinder
elFinder file manager for Yii 2
Stars: ✭ 21 (-40%)
Mutual labels:  yii2, yii2-extension
yii2-jwt-user
JWT (JSON Web Token) User component for Yii 2
Stars: ✭ 16 (-54.29%)
Mutual labels:  yii2, yii2-extension
Yii2 Helpers
Collection of useful helper functions for Yii Framework 2.0
Stars: ✭ 16 (-54.29%)
Mutual labels:  yii2, yii2-extension
yii2-telegram
Support chat for site based on Telegram bot
Stars: ✭ 49 (+40%)
Mutual labels:  yii2, yii2-extension
Yii2 C3 Chart
Yii2 wrapper for D3-based reusable chart library
Stars: ✭ 9 (-74.29%)
Mutual labels:  yii2, yii2-extension
yii2-queuemanager
Yii2 Queue Manager (Analytic & Monitor)
Stars: ✭ 18 (-48.57%)
Mutual labels:  yii2, yii2-extension
Yii2 Telegram Log
Telegram log target for Yii 2
Stars: ✭ 24 (-31.43%)
Mutual labels:  yii2, yii2-extension
Yii2 Many To Many
Implementation of Many-to-many relationship for Yii 2 framework
Stars: ✭ 30 (-14.29%)
Mutual labels:  yii2, yii2-extension
yii2-facades
Facades for Yii 2
Stars: ✭ 21 (-40%)
Mutual labels:  yii2, yii2-extension
Yii2 Bx Slider
bx-slider.js wrapper for yii2.
Stars: ✭ 11 (-68.57%)
Mutual labels:  yii2, yii2-extension
yii2-star-rating
Star rating widget based on jQuery Raty
Stars: ✭ 16 (-54.29%)
Mutual labels:  yii2, yii2-extension
Yii2 Google Maps Markers
Google Maps Markers Widget for Yii2
Stars: ✭ 16 (-54.29%)
Mutual labels:  yii2, yii2-extension
filedb
ActiveRecord for static data definitions based on files
Stars: ✭ 72 (+105.71%)
Mutual labels:  yii2, yii2-extension
yii2-merit
Reputation engine for Yii2 用于实现积分,等级功能的设计
Stars: ✭ 16 (-54.29%)
Mutual labels:  yii2, yii2-extension
collection
Basic collection library for Yii Framework 2.0
Stars: ✭ 29 (-17.14%)
Mutual labels:  yii2, yii2-extension
Yii2 Gentelella
Free admin template for backend
Stars: ✭ 266 (+660%)
Mutual labels:  yii2, yii2-extension

ImageAttachment

This extension intended to handle images associated with model.

Extensions provides user friendly widget, for image upload and removal.

Yii2 image attachement screenshot

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.

Either run

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

or add

"zxbodya/yii2-image-attachment": "*@dev"

to the require section of your composer.json file.

Usage

Add ImageAttachmentBehavior to your model, and configure it, create folder for uploaded files.

public function behaviors()
{
    return [
        '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),
                        ['jpeg_quality' => 80], // options used when saving image (Imagine::save)
                    ];
                },
            ]
        ]
    ];
}

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

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.

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

Done! Now, you can use it in other places in app too:

if ($model->getBehavior('coverBehavior')->hasImage()) {
    echo Html::img($model->getBehavior('coverBehavior')->getUrl('medium'));
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].