This is a lightweight extension for the well known phpThumb library. There are a lot of extensions out there providing a lot more functionality but they can be total overkill for just creating some thumbnails and saving them to disk. If you just want a simple wrapper for phpThumb then this extension is the right one.
Requirements ¶
Yii 1.1.x
Usage ¶
In your main.php
'phpThumb'=>array(
'class'=>'ext.EPhpThumb.EPhpThumb',
'options'=>array(optional phpThumb specific options are added here)
),
$thumb=Yii::app()->phpThumb->create('../images/myImage.jpg');
$thumb->resize(100,100);
$thumb->save('../images/thumb.jpg');
For more information visit the phpThumb documentation.
Good job
Exactly what I needed. Thank you! Been using WideImage before, but for simple thumbnails creation phpThumb is so much better.
If you don't want to put it in main.php
Yii::import("ext.EPhpThumb.EPhpThumb"); $thumb=new EPhpThumb(); $thumb->init(); //this is needed //chain functions $thumb->create('../images/BIG.jpg') ->resize(200,200); ->save('../images/SMALL.jpg');
Nice work!
Exactly what I needed. Thank you! Been using CThumb before, but for simple thumbnails creation phpThumb is so much better.
Caching
It'd be to detect if a thumbnail already exists in a cache
Polish version
Polish version here http://blog.laret.pl/2012/10/22/yii-phpthumb-tworzenie-miniatur/
Optimize adaptiveResize funtion with adaptiveResizePercent
If you are using the adaptiveResize, funcion as the documentation says, images are always cropped from the center.
If you wanna crop from the top/bottom=portrait left/right=landscape, you can use percentages with the adaptiveResizePercent function by sending a third parameter... how ever the creator of this extension didnt included the already available adaptiveResizePercent function. So add it to the EThumbnail.php file:
/** * Resizes the image to the given dimensions as close as possible and from a desired x/y percent coordinate, * then crops it from the specified percent * Portrait images: 1=top, 50=center, 100=bottom * Landscape images: 1=left, 50=center, 100=right * @param integer $width the width to crop the image to. * @param integer $height the height to crop the image to. * @param integer $percent the percent to determine the crop x/y coordinates. * @return EThumbnail */ public function adaptiveResizePercent($width,$height,$percent=50) { $this->_thumbnail=$this->_thumbnail->adaptiveResizePercent($width,$height,$percent); return $this; }
Thanks
It works well.Thanks
$thumb=Yii::app()->phpThumb->create('../images/myImage.jpg'); $thumb->resizePercent(50);//Percentage $thumb->save('../images/thumb.jpg');
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.