imagefly Extension which helps generation of thumbnails according to need. On the Fly.

  1. Requirements
  2. Instalation
  3. Usage
  4. Controller
  5. Models
  6. Resources

Images Thumbnails on the Fly.

Extension which helps generation of thumbnails according to need.

Besides creating files dynamically.

Requirements

Yii 1.1 or above.

Instalation

  1. Unzip the file inside the extension folder.

  2. Add to your config / main.php the following line:

'import' => array (
   ...
   'application.extensions.ImageFly.components.*'
   ...
);

Usage

//Normal mode
<img src='<?php echo ImageFly::Instance()->get($model, 'attr', ImageFly::MEDIUM, Image::MEDIUM);?>'/>
---
<img src='<?php echo ImageFly::Instance()->get($model, 'attr', ImageFly::MEDIUM);?>'/>
---
<img src='<?php echo ImageFly::Instance()->get($model, 'attr', 600, 745);?>'/>

//Using Chtml
echo CHtml::image(ImageFly::Instance()->get($model, 'attr', $x, $y));

Controller

Eg.

public function actionCreate()
{
       $model=new Post;
       if(isset($_POST['Post']))
       {
          $model->attributes=$_POST['Post'];
          $model->image = CUploadedFile::getInstance($model, 'image');
                    
          if($model->validate())
          {
              $model->image->saveAs(ImageFly::Instance()->getPath($model, 'image'));

            if($model->save())
            {
                 $this->redirect(array('view','id'=>$model->id));
            }
         }
      }

      $this->render('create',array(
	 'model'=>$model,
      ));
}

Models

Your model should have the following attributes

$model->imagePath
$model->imagePathThumb

Where the attribute ImagePath is the path of the original image and imagePathThumb is the path where the thumbnail will be created.

eg:

public $imagePath = 'user/';
public $imagePathThumb = 'user/thumb/';
...
protected function beforeSave() {
  if ($this->image instanceof CUploadedFile) {
      $this->image = md5($this->image->getName()) . "." . $this->image->getExtensionName();
  }
  return parent::beforeSave();
}

Resources

1 0
3 followers
1 108 downloads
Yii Version: Unknown
License: BSD-2-Clause
Category: Others
Developed by: Vinny.freire
Created on: Jul 25, 2013
Last updated: 4 years ago

Downloads

show all

Related Extensions