Hi chandran,
if u don’t mind please check my code is it crt or not.
controller:
public function actionUpdate($id)
{
$this->layout='//layouts/profilecontent';
$model=$this->loadModel($id);
$profilePic = 'shadow.png';
if(isset($_POST['User']))
{
$model->attributes=$_POST['User'];
$rnd = rand(0,9999); // generate random number between 0-9999
$uploadedFile=CUploadedFile::getInstance($model,'profilepic');
if($uploadedFile!=null) {
$fileName = "{$rnd}-{$uploadedFile}"; // random number + file name
$model->profilepic = $fileName;
}
$valid_format="jpg,png,jpeg,gif";
if($model->save()&&$valid_format) {
if(!empty($uploadedFile)) {
$uploadedFile->saveAs(Yii::app()->basePath.'/../images/Editimage/'.$fileName);
Yii::import('ext.jcrop.EJCropper');
$jcropper = new EJCropper();
$jcropper->thumbPath = Yii::app()->basePath.'/../images/Editimage/'.$fileName;
// some settings ...
$jcropper->jpeg_quality = 95;
$jcropper->png_compression = 8;
// get the image cropping coordinates (or implement your own method)
$coords = $jcropper->getCoordsFromPost('uploadPreview');
// returns the path of the cropped image, source must be an absolute path.
$thumbnail = $jcropper->crop(Yii::app()->basePath.'/../images/thumbs/', $coords);
}
$this->redirect(array('view','id'=>$model->id));
}
}
$this->profileInfo = $this->renderPartial('profileInfo',array('model'=>$model),true);
$this->render('update',array(
'model'=>$model,
));
}
view:
<?php
$this->widget(‘ext.jcrop.EJcrop’, array(
//
// Image URL
'url' => Yii::app()->baseUrl.'/images/Editimage/'.$model->profilepic,
//
// ALT text for the image
'alt' => 'Crop This Image',
//
// options for the IMG element
'htmlOptions' => array('id' => 'uploadPreview','onclick'=>"return image();"),
//
// Jcrop options (see Jcrop documentation)
'options' => array(
'minSize' => array(50, 50),
'aspectRatio' => 1,
'onRelease' => "js:function() {ejcrop_cancelCrop(this);}",
),
// if this array is empty, buttons will not be added
'buttons' => array(
'start' => array(
'label' => Yii::t('promoter', 'Adjust thumbnail cropping'),
'htmlOptions' => array(
'class' => 'myClass',
'style' => 'color:red;', // make sure style ends with « ; »
)
),
'crop' => array(
'label' => Yii::t('promoter', 'Apply cropping'),
),
'cancel' => array(
'label' => Yii::t('promoter', 'Cancel cropping')
)
),
// URL to send request to (unused if no buttons)
'ajaxUrl' => Yii::app()->createAbsoluteUrl('user/update&id='.($model->id)),
//
// Additional parameters to send to the AJAX call (unused if no buttons)
'ajaxParams' => array('someParam' => 'someValue'),
));
?>