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).
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?
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; }
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; }
is thie free for everything
is thie free for everything?
thanks for share!
so nice
error in the var
in resize function in EasyPhpThumb.php you have to correct the height var, there's an error transcription, good extension
good
:)
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.
Can't make it work..
I followed the installation process as defined here and trying to use code in view but got error.
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.
Undefined index: JPG Support
Same error. there is no in $gdInfo "JPG Support", only "JPEG Support"
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
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 ??
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.