All Projects → zxbodya → Yii2 Gallery Manager

zxbodya / Yii2 Gallery Manager

Projects that are alternatives of or similar to Yii2 Gallery Manager

Yii2 Aws S3
An Amazon S3 component for Yii2
Stars: ✭ 86 (-4.44%)
Mutual labels:  yii2, yii2-extension
Yii2 Rabbitmq
RabbitMQ Extension for Yii2
Stars: ✭ 52 (-42.22%)
Mutual labels:  yii2, yii2-extension
Yii2 Lifecycle Behavior
Define the lifecycle of a model by defining allowed status changes.
Stars: ✭ 47 (-47.78%)
Mutual labels:  yii2, yii2-extension
Csv Grid
Yii2 extension for CSV export
Stars: ✭ 83 (-7.78%)
Mutual labels:  yii2, yii2-extension
Yii2 Psr Log Target
Yii 2.0 log target that is able to write messages to PSR-3 compatible logger
Stars: ✭ 58 (-35.56%)
Mutual labels:  yii2, yii2-extension
Yii2 Relation Trait
Yii 2 Models add functionality for load with relation, & transactional save with relation PLUS soft delete/restore feature
Stars: ✭ 47 (-47.78%)
Mutual labels:  yii2, yii2-extension
Yii2 Social Share
With this extension you can share data from your web pages to any social network!
Stars: ✭ 48 (-46.67%)
Mutual labels:  yii2, yii2-extension
Yii2 Image Attachment
This extension intended to handle images associated with model.
Stars: ✭ 35 (-61.11%)
Mutual labels:  yii2, yii2-extension
Php frameworks analysis
php框架源码分析
Stars: ✭ 57 (-36.67%)
Mutual labels:  yii2, yii2-extension
Yii2 Sortable Widgets
🍨 Rubaxa/Sortable for Yii2
Stars: ✭ 54 (-40%)
Mutual labels:  yii2, drag-and-drop
Ar Linkmany
ActiveRecord behavior for saving many-to-many relations
Stars: ✭ 83 (-7.78%)
Mutual labels:  yii2, yii2-extension
Yii2 Collection
Collection extension for Yii 2
Stars: ✭ 62 (-31.11%)
Mutual labels:  yii2, yii2-extension
Yii2 Cms
Simple CMS extension
Stars: ✭ 42 (-53.33%)
Mutual labels:  yii2, yii2-extension
Yii2 Schemadump
Generate the schema from an existing database.
Stars: ✭ 78 (-13.33%)
Mutual labels:  yii2, yii2-extension
Yii2 Gravatar
Gravatar Widget for Yii Framework 2
Stars: ✭ 36 (-60%)
Mutual labels:  yii2, yii2-extension
Yii2 Editable
Editable widget and column for gridview.
Stars: ✭ 47 (-47.78%)
Mutual labels:  yii2, yii2-extension
Yii2 User
[ABANDONED] Flexible user registration and authentication module for Yii2
Stars: ✭ 946 (+951.11%)
Mutual labels:  yii2, yii2-extension
Yii2 Many To Many
Implementation of Many-to-many relationship for Yii 2 framework
Stars: ✭ 30 (-66.67%)
Mutual labels:  yii2, yii2-extension
Config
Yii2 application runtime configuration support
Stars: ✭ 54 (-40%)
Mutual labels:  yii2, yii2-extension
Sitemap
Site map creation support
Stars: ✭ 59 (-34.44%)
Mutual labels:  yii2, yii2-extension

Gallery Manager usage instructions

Yii2 port of https://github.com/zxbodya/yii-gallery-manager

(frontend part mostly without changes, but backend was rewritten almost completely)

Gallery manager screenshots (yii 1.x version, new one has bootstrap 3 styles):

GalleryManager images list

Few more screenshots: drag & drop upload, editing image information, upload progress,

Features

  1. AJAX image upload
  2. Optional name and description for each image
  3. Possibility to arrange images in gallery
  4. Ability to generate few versions for each image with different configurations
  5. Drag & Drop

Decencies

  1. Yii2
  2. Twitter bootstrap assets (version 3)
  3. Imagine library
  4. JQuery UI (included with Yii)

Installation:

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist zxbodya/yii2-gallery-manager "*@dev"

or add

"zxbodya/yii2-gallery-manager": "*@dev"

to the require section of your composer.json file.

Usage

Prepare

Add migration to create table for images:

class m150318_154933_gallery_ext
    extends zxbodya\yii2\galleryManager\migrations\m140930_003227_gallery_manager
{

}

Or better - copy migration to you application(but be sure to remove namespace from it - it should be in global namespace)

Add configurations for upload and store images

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

use zxbodya\yii2\galleryManager\GalleryBehavior;

class Product extends \yii\db\ActiveRecord 
{
...
public function behaviors()
{
    return [
         'galleryBehavior' => [
             'class' => GalleryBehavior::className(),
             'type' => 'product',
             'extension' => 'jpg',
             'directory' => Yii::getAlias('@webroot') . '/images/product/gallery',
             'url' => Yii::getAlias('@web') . '/images/product/gallery',
             'versions' => [
                 'small' => function ($img) {
                     /** @var \Imagine\Image\ImageInterface $img */
                     return $img
                         ->copy()
                         ->thumbnail(new \Imagine\Image\Box(200, 200));
                 },
                 'medium' => function ($img) {
                     /** @var \Imagine\Image\ImageInterface $img */
                     $dstSize = $img->getSize();
                     $maxWidth = 800;
                     if ($dstSize->getWidth() > $maxWidth) {
                         $dstSize = $dstSize->widen($maxWidth);
                     }
                     return $img
                         ->copy()
                         ->resize($dstSize);
                 },
             ]
         ]
    ];
}

See also documentations of imagine for image transformations.

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

use zxbodya\yii2\galleryManager\GalleryManagerAction;

class ProductController extends Controller
{
...
public function actions()
{
    return [
       'galleryApi' => [
           'class' => GalleryManagerAction::className(),
           // mappings between type names and model classes (should be the same as in behaviour)
           'types' => [
               'product' => Product::className()
           ]
       ],
    ];
}

Add ImageAttachmentWidget somewhere in you application, for example in editing from.

use zxbodya\yii2\galleryManager\GalleryManager;

/* @var $this yii\web\View */
/* @var $model Product */
?>
...
<?php
if ($model->isNewRecord) {
    echo 'Can not upload images for new record';
} else {
    echo GalleryManager::widget(
        [
            'model' => $model,
            'behaviorName' => 'galleryBehavior',
            'apiRoute' => 'product/galleryApi'
        ]
    );
}
?>

Done!

Get uploaded images

Now, you can use uploaded images from gallery like following:

foreach($model->getBehavior('galleryBehavior')->getImages() as $image) {
    echo Html::img($image->getUrl('medium'));
}

Options

Using non default table name for gallery images(default is {{%gallery_image}}):

  1. Add migration that will create table you need
  2. Change tableName property in behavior configuration
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].