Skip to content

Provides methods for the dynamic manipulation of images. Various image formats such as JPEG, PNG, and GIF can be resized, cropped, rotated.

License

Notifications You must be signed in to change notification settings

highestgoodlikewater/yii2-image

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yii2 Image Component

Provides methods for the dynamic manipulation of images. Various image formats such as JPEG, PNG, and GIF can be resized, cropped, rotated.

To use this extension, you have to configure the Connection class in your application configuration:

//configure component:
return [
    //....
    'components' => [
        'image' => [
            'class' => 'yii2mod\image\ImageComponent',
        ],
    ]
];

//add behavior to the model 
public function behaviors()
    {
        return [
            'image' => [
                'class' => ImageBehavior::className(),
                'pathAttribute' => 'path'
            ],
        ];
    }
    
// add image action to SiteController
public function actions()
{
    return [
        'image' => 'yii2mod\image\actions\ImageAction'
    ];
}
 

Usage example:

$imageModel->url('home'); // home is the type of photo, depending on type resize/crop/watermark/etc actions will happen

Configuring image types (yii params configuration section should be used):

'params' => [
        .....
        'image' => [
            'medium' => [
                'thumbnail' => [
                    'box' => [194, 194],
                    'mode' => 'outbound'
                ],
                'visible' => 'user' //checking role before outputing url
            ],
            'home' => [
                'thumbnail' => [
                    'box' => [640, 480],
                    'mode' => 'inset'
                ],
                'watermark' => [
                    'watermarkFilename' => '@app/web/images/watermark.png'
                ],

            ]
        ]
    ],

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require imagine/imagine "0.6.2 as 0.5.1"
php composer.phar require --prefer-dist yii2mod/yii2-image "*"

or add

"imagine/imagine": "0.6.2 as 0.5.1",
"yii2mod/yii2-image": "*"

to the require section of your composer.json.

About

Provides methods for the dynamic manipulation of images. Various image formats such as JPEG, PNG, and GIF can be resized, cropped, rotated.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%