Yii 1.1: easyphpthumb

Wrapper on PHP Thumb 3.0 image manipulation library
8 followers

This extension is simple and really easy to use wrapper on excellent PHP Thumb 3.0 library.

Resources

Documentation

Requirements

  • Yii 1.0.9 or above

Installation

  • Extract the release file under protected/extensions

Supported operations

  • resize(width, height)
  • resizePercent(percent)
  • crop(x,y,width,heigh)

Usage

Depending on frequency of usage you can use it in two ways: * for high usage (as component defined in config/main.php) * for low usage (instantiate where use)

1). Component approach:

Definition - config/main.php

..
// application components
'components'=>array(
        ..       
        'thumb'=>array(
            'class'=>'ext.phpthumb.EasyPhpThumb',
        ),
),
..

Usage:

Yii::app()->thumb->setThumbsDirectory('/images/thumbs');
 
Yii::app()->thumb
->load(Yii::getPathOfAlias('webroot')."/images/".$filename)
->crop($area['x'],$area['y'],$area['width'],$area['height'])
->save($area['name'].".gif", "GIF");

2). In situ approach:

Yii::import('ext.phpthumb.EasyPhpThumb');
$thumbs = new EasyPhpThumb();
$thumbs->init();
$thumbs->setThumbsDirectory('/images/thumbs');
 
$thumbs
->load(Yii::getPathOfAlias('webroot')."/images/".$filename)
->crop($area['x'],$area['y'],$area['width'],$area['height'])
->save($area['name'].".gif", "GIF");

Change Log

October 25, 2009

  • Initial release (PHP Thumb 3.0).

Total 12 comments

#5588 report it
kareem zok at 2011/10/22 03:24pm
Given format not found in allowed

i implemented extension in my application and all work fine until i uploaded a GIF image . but i got this error "Given format not found in allowed (GIF, JPG, PNG) - received GIF" . and in extension said its allowed this format so how come i get an error ?? any help plz ??

#5328 report it
Alex Adams at 2011/10/04 10:06pm
Size limits?

I wonder if there are size limits to this tool. I have this installed and working fine on sub-1MB files, but it goes to an empty white page when I try it with a 6MB file. I am uploading and storing the original image in full size using CUploadedFile, then making 2 resized copies using easyphpthumb. The upload is working on the 6MB file, but the phpthumb stuff is not.

Any ideas?

Excellent tool by the way.

Alex


The next day I investigated further...

This is from my post on the extensions section of the forum:

I have easyphpthumb installed and working. But, it bombs on some files. At first I thought that it was file size, but in subsequent tests it appears that this is not the case.

The resizing is done in actionCreate and actionUpdate in the Image content type controller. When it works right, after the original file is saved it creates a thumbnail (64x64) and a web display size (532x399) using adaptiveResize. When it doesn't work, it fails to render the Image view page and shows only an empty white page.

I exported an image in iPhoto (originated in a camera) in all possible formats, sizes and resolutions. Original, current, PNG, and all full sized options are not accepted. All others are accepted. Some of the ones accepted are larger than those that are not accepted.

I tried to open the unaccepted ones in Fireworks, resize them a bit and copy them to a new file. All were not accepted, jpg and png.

I downloaded a few images from Wikipedia. Some were accepted. Some were not. Some were accepted after being opened in Fireworks, slightly resized and then saved in jpg and png.

Does anyone know what's going one here?

Thanks,

Alex

#5121 report it
mnogokotin at 2011/09/16 02:35am
Undefined index: JPG Support

Same error. there is no in $gdInfo "JPG Support", only "JPEG Support"

#3222 report it
Khan at 2011/03/26 09:38am
Can't make it work..

I followed the installation process as defined here and trying to use code in view but got error.

Undefined index: JPG Support

My codes in view are as under

$baseUrl=Yii::app()->request->baseUrl;
 
$filename=$baseUrl .'/test.jpg';
$area='';
 
Yii::app()->thumb->setThumbsDirectory('/images/thumbs');
 Yii::app()->thumb
 
->load(Yii::getPathOfAlias('webroot')."/images/".$filename)
->crop($area['100'],$area['100'],$area['200'],$area['200'])
->save($area['11'].".gif", "GIF");

Also if I change my file from 'test.jpg' to 'test.png' get another error

Uninitialized string offset: 100

With following codes

$baseUrl=Yii::app()->request->baseUrl;
 
$filename=$baseUrl .'/test.png';
$area='';
 
Yii::app()->thumb->setThumbsDirectory('/images/thumbs');
 Yii::app()->thumb
 
->load(Yii::getPathOfAlias('webroot')."/images/".$filename)
->crop($area['100'],$area['100'],$area['200'],$area['200'])
->save($area['11'].".gif", "GIF");

Can anybody help me in this situation.

#414 report it
juniorplenty at 2010/06/09 03:30pm
ImageMagick driver requires CArray

When I use the ImageMagick driver, yii coughes up an error stating that CArray can't be found - this is referenced on line 69 of the driver. Is this an outdated yii component?

#435 report it
Makea at 2010/06/02 04:54pm
php Thumbnailer Options

I couldn't figure out how to use php thumbnailer options, so I modified the load function:

public function load($imagePath,$options=''){
// Modify to allow options to be set
if(is_array($options)) {
      $image = PhpThumbFactory::create($imagePath,$options);
}
else {
  $image = PhpThumbFactory::create($imagePath);
}
    $this->image = $image;
    return $this;
}
#693 report it
jerry2801 at 2010/03/17 12:04pm
setThumbsDirectory problem!
public function setThumbsDirectory($relPath){
 
    $webrootDir = YiiBase::getPathOfAlias('webroot');
    if (is_link($webrootDir)) {
        $webrootDir = readlink($webrootDir);
    }
 
    $destDir = $webrootDir.$relPath;
 
    if (!is_dir($destDir) && !is_writeable($destDir)) {
        throw new CException('Target directory('.$destDir.') does not exist or is not writeable.');
    }
 
    $this->thumbsDirectory = $destDir;
 
}

sometime, i want special the full path, so, i think it can be change to:

public function setThumbsDirectory($destDir){
    if(!is_dir($destDir))
    {
        $webrootDir = YiiBase::getPathOfAlias('webroot');
        if (is_link($webrootDir)) {
            $webrootDir = readlink($webrootDir);
        }
        $destDir = $webrootDir.$destDir;
    }
 
    if (!is_dir($destDir) && !is_writeable($destDir)) {
        throw new CException('Target directory('.$destDir.') does not exist or is not writeable.');
    }
 
    $this->thumbsDirectory = $destDir;
 
}
#1107 report it
jackiesun at 2009/12/07 09:12pm
is thie free for everything

is thie free for everything?

#1160 report it
jerry2801 at 2009/11/20 09:02am
thanks for share!

so nice

#1193 report it
jackass at 2009/11/04 09:25am
error in the var

in resize function in EasyPhpThumb.php you have to correct the height var, there's an error transcription, good extension

#1208 report it
Zolter at 2009/10/27 03:51am
good

:)

#1210 report it
someone at 2009/10/26 10:29am
Add ability switch use library

I advice to add ability in configuration below class defining which library to use: GD or Imagick, phpThumb support this feature.

Leave a comment

Please to leave your comment.

Create extension
  • Yii Version: 1.1
  • License: New BSD License
  • Developed by: KEo
  • Category: File System
  • Votes: +13
  • Downloaded: 2,515 times
  • Created on: Oct 25, 2009
  • Last updated: never