. . .

Upload and resize image using YII

Published: October 6, 2010

Download and extract this file in protected/extensions directory.
 
In config/main.php file, add the following element to components array 
'image'=>array(
'class'=>'application.extensions.image.CImageComponent',
'driver'=>'GD',
) 

 

Now in action, insert the following code and modify paths

$model->Picture = CUploadedFile::getInstance($model,'Picture');
if( is_object($model->Picture) )
{
    mkdir(getcwd().'/images/users/'.$model->Id."/");
    $name = getcwd().'/images/users/'.$model->Id."/".$model->Picture->getName();
    $model->Picture->saveAs($name);
    $image = Yii::app()->image->load($name);
    $image->resize(50, 50);
    $image->save();
}

 

 Source: http://docs.kohanaphp.com/libraries/image

Don't forget to share this post

    Let's Build Digital Excellence Together


    • Cost Efficient Solutions.
    • Minimal Timelines.
    • Effective Communication.
    • High Quality Standards.
    • Lifetime Support.
    • Transparent Execution.
    • 24/7 Availability.
    • Scalable Teams.

    Join Our 200+ Happy Clients Across Globe


    Free Consultation.

      Do you need help in strategy, innovation or growth of your startup/business? Experts from our team will get in touch with you.

      Please do not post jobs/internships inquiries here.