how to get image properties on upload

how can i get height and width of an image on upload.Here is my sample code.

My Model class rules




public function rules()

{

	return array(

		array('image, image_name, height, width, type, category', 'required'),

                array('image', 'file', 'types'=>'jpg, gif, png'),

		array('height, width, type, hide, category', 'numerical', 'integerOnly'=>true),

		array('image_name', 'length', 'max'=>30),

		array('id, image, image_name, height, width, type, hide, category', 'safe', 'on'=>'search'),

	);

}



My Controller action




public function actionCreate()

{

	$model=new Images;

	if(isset($_POST['Images']))

	{

		$model->attributes=$_POST['Images'];

                if($file=CUploadedFile::getInstance($model,'image'))

                {

                      $model->image_name=$file->name;

                      $model->type=$file->type;

                      $model->height=$file->height;

                }

                      $model->image=$file;

		if($model->save())

			$this->redirect(array('view','id'=>$model->id));

	}


	$this->render('create',array(

			'model'=>$model,

                        'categories'=>$categories,

	));

}



Here i am trying to load an image to database with this piece of code, but before saving image to database i need some image properties like (height, width, size , image name), for image searching purpose where as i am getting image name but not the remaining properties.

This extension looks like it will provide you with the functionality you need.

http://www.yiiframework.com/extension/image/

It uses the Kohana image library, see http://docs.kohanaphp.com/libraries/image#get

A simple getimagesize() will do the job too.

I am trying in two different ways to get image properties on image upload one using getimagesize() and using image extension. when i try to do this both ways are showing image not found. Here my below code.




public function actionCreate()

{

	$model=new Images;

                

	if(isset($_POST['Images']))

	{

		$model->attributes=$_POST['Images'];

                $file=CUploadedFile::getInstance($model,'image');

                $imagevariables=getimagesize($file);

                print_r($imagevariables);


                $file1=Yii::app()->image->load($file);


                $model->image_name=$file1->name;

                $model->type=$file1->type;

                $model->height=$file1->height;

                $model->image=$file;

		if($model->save())

			$this->redirect(array('view','id'=>$model->id));

	}

		$this->render('create',array('model'=>$model,));

}



Can some one help me out on this.

Try


$imagevariables = getimagesize($file->tempName);

I am able to upload my images to database but i am not able to view the images in CGridView and CDetailView

in my CGridView i am trying to use image extension to show it in thumbnail format by re-size it.




array(

      'name'=>'image',

      'type'=>'image',

      'value'=>'Yii::app()->image->load(@$data->image)->resize(100, 100)->quality(50)->render()',

),



In this case its throwing an error saying that image file not found.

How can i show my image in CGridView and CDetailView by using image extension.

Can some one help me out on resize blob image.

My Controller action goes like below




public function actionDisplaySavedImage()

        {

            $model=$this->loadModel($_GET['id']);


            header('Pragma: public');

            header('Expires: 0');

            header('Cache-Control: must-revalidate, post-check=0, pre-check=0');

            header('Content-Transfer-Encoding: binary');

            header('Content-length: '.$model->file_size);

            header('Content-Type: '.$model->file_type);

            header('Content-Disposition: inline; filename='.$model->file_name);


                echo $model->file_content;

        }



I am able to print the image like below




echo CHtml::image(Yii::app()->urlManager->createUrl(

                        'images/DisplaySavedImage',

                        array(

                                'id'=>$data->id,

                                "height"=>100, "width"=>100

                        )

                ));



But i am not able to resize this. I need to consider the height and width which i will pass as parameters then resize the image according to height and width specified.