Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Object-Event-Oriented Yii extension for Image manipulation
PHP
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
fills
gd
gmagick
imagick
LICENSE
README.md
YiiImage.php
YiiImageBox.php
YiiImageColor.php
YiiImageDrawer.php
YiiImageDrawerBehavior.php
YiiImageDrawerEvent.php
YiiImageDrawerEventOnDrawArc.php
YiiImageDrawerEventOnDrawChord.php
YiiImageDrawerEventOnDrawDot.php
YiiImageDrawerEventOnDrawEllipse.php
YiiImageDrawerEventOnDrawLine.php
YiiImageDrawerEventOnDrawPieSlice.php
YiiImageDrawerEventOnDrawPolygon.php
YiiImageDrawerEventOnDrawText.php
YiiImageDrawerEvents.php
YiiImageDriver.php
YiiImageDriverBehavior.php
YiiImageDriverEvent.php
YiiImageDriverEventOnAfterCreate.php
YiiImageDriverEventOnAfterFont.php
YiiImageDriverEventOnAfterLoad.php
YiiImageDriverEventOnAfterOpen.php
YiiImageDriverEventOnAfterRead.php
YiiImageDriverEventOnBeforeCreate.php
YiiImageDriverEventOnBeforeFont.php
YiiImageDriverEventOnBeforeLoad.php
YiiImageDriverEventOnBeforeOpen.php
YiiImageDriverEventOnBeforeRead.php
YiiImageDriverEvents.php
YiiImageFill.php
YiiImageFont.php
YiiImageFontBehavior.php
YiiImageFontEvent.php
YiiImageFontEventOnAfterBox.php
YiiImageFontEventOnBeforeBox.php
YiiImageFontEvents.php
YiiImagePoint.php
YiiImageProvider.php
YiiImageProviderBehavior.php
YiiImageProviderEvent.php
YiiImageProviderEventOnAfterBinary.php
YiiImageProviderEventOnAfterCopy.php
YiiImageProviderEventOnAfterHistogram.php
YiiImageProviderEventOnAfterMask.php
YiiImageProviderEventOnAfterThumbnail.php
YiiImageProviderEventOnApplyMask.php
YiiImageProviderEventOnBeforeBinary.php
YiiImageProviderEventOnBeforeCopy.php
YiiImageProviderEventOnBeforeHistogram.php
YiiImageProviderEventOnBeforeMask.php
YiiImageProviderEventOnBeforeThumbnail.php
YiiImageProviderEventOnCrop.php
YiiImageProviderEventOnFill.php
YiiImageProviderEventOnFlipHorizontally.php
YiiImageProviderEventOnFlipVertically.php
YiiImageProviderEventOnPaste.php
YiiImageProviderEventOnResize.php
YiiImageProviderEventOnRotate.php
YiiImageProviderEventOnSave.php
YiiImageProviderEventOnShow.php
YiiImageProviderEvents.php
YiiImageThumbnailModes.php

README.md

Introduction of YiiImage

Object-Event-Oriented Yii extension for Image manipulation

Installation and Configuring

  1. Extract those files to folder "extention/yii-image"
  2. Set configuration in main config.

<?php
// protected/configs/main.php

return array(

    'import' => array(
        /**

        ...

        */
        'ext.yii-image.*',
    ),

    'components' => array(
        /**

        ...

        */
        'image' => array(
            'class' => 'YiiImage',
            'activeDriverName' => 'gd', // avaliable: gd, imagick, gimagick
        ),
    ),
);
  1. Available driver names:

    • gd
    • imagick
    • gmagick

Using


<?php

$img = Yii::app()->image->create(new YiiImageBox(800, 600));

$drawer = $img->draw();
$drawer->onBeforeDrawPolygon = function (YiiImageDrawerEventOnDrawPolygon $event)
{
    var_dump($event->color);
};
$drawer->line(new YiiImagePoint(3, 3), new YiiImagePoint(50, 50), new YiiImageColor('#00FF00'))
       ->ellipse(new YiiImagePoint(300, 300), new YiiImageBox(200, 400), new YiiImageColor('#FF0000'))
       ->polygon(array(
            new YiiImagePoint(200, 400),
            new YiiImagePoint(300, 400),
            new YiiImagePoint(300, 410),
            new YiiImagePoint(200, 430),
            new YiiImagePoint(210, 330),
        ), new YiiImageColor('#0000FF'));

$img->save($path, array('format' => 'png'));

Events and Behaviors

The names of all available event can be found in the following classes:

* YiiImageDriverEvents
* YiiImageProviderEvents
* YiiImageDrawerEvents
* YiiImageFontEvents

Events can be attached as:

  1. Closure/function/method

<?php

$img = Yii::app()->image->create(new YiiImageBox(800, 600));

/**
 * Closure.
 */
$img->onBeforeSave = function(YiiImageProviderEventOnSave $event)
{
    if(file_exists($event->savePath)) {
        throw new Exception(sprintf('File "%s" already exists!', $event->savePath));
    }
};

/**
 * Object.
 */
$model = new UserModel();
$img->onBeforeSave = array($model, 'beforeSaveImageCheckFreeSpace');
  1. Behaviors.

To expand the existing base classes available behaviors:

* YiiImageDriverBehavior
* YiiImageProviderBehavior
* YiiImageDrawerBehavior
* YiiImageFontBehavior 
Something went wrong with that request. Please try again.