Imagecreatefromjpeg() With Yii::app()->Basepath

Hi guys, i’ve been stuck on this for a while now.

Im sure the solution is easy, i just cant see it.

I have a user profile-picture upload.

The image gets uploaded correctly, but i want to resize it to several sizes.

i made a function:


        function imageResize($file, $ext, $width, $save_path)

        {

            $size = getimagesize($file);

            $ratio = $size[1]/$size[0];

            $height = round($width*$ratio);

            $image = imagecreatetruecolor($width, $height);

            

            if($ext == 'jpg' || $ext == 'jpeg') $new = imagecreatefromjpeg($file);

            

            imagecopyresized($new, $image, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);

            if($ext == 'jpg' || $ext == 'jpeg') imagejpeg($new, $save_path);

            imagedestroy($image);

            return true;

        }

And i deliver the $file and $savepath by Yii::app()->basePath, as the images is stored in protected folder.

It does not return any errors, just a blank screen. But by troubleshooting with die(‘sofarsogood’); i’ve narrowed the problem down to the line imagecreatefromjpeg($file), and i suspect the basepath url is invalid here.

Any suggestions?

thanks in advance.

Try

Yii::getPathOfAlias(‘webroot’).’/folder.To.Image’

Thanks, alex.

But that does not help, as i have the images in protected/upload/.

you can give like




Yii::app()->getPathOfAlias('application').'/upload/'