Hi @all,
I tried to use the Image extension of Yii. Installed the extension as described at the official extension site.
My main.php looks like this:
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
'application.modules.user.models.*',
'application.modules.user.components.*',
'application.modules.rights.*',
'application.modules.rights.components.*',
'application.helpers.*',
), [...]
'image'=>array(
'class'=>'application.extensions.image.CImageComponent',
// GD or ImageMagick
'driver'=>'GD',
// ImageMagick setup path
//'params'=>array('/extensions/image/drivers'),
),
and I tried to use the extension in my ImageController.php for resizing an Image submitted by an upload form:
ImageController.php actionCreate() method:
if(isset($_POST['Image']))
{
$model->attributes=$_POST['Image'];
if($model->validate()) {
// upload image file
$model->imgName = CUploadedFile::getInstance($model, 'imgName');
if($model->imgName == null) {
$model->addError('imgName', 'Please upload a picture.');
}
else {
// CVarDumper::dump($model->imgName, 10, true);
// create a temporary copy of the Uploaded File object
$temp_img = $model->imgName;
$imgDir = Yii::app()->params['imgDir'];
// @todo: potentially unsafe as imgName could be used for hijacking
$imgName_new = Yii::app()->user->getId().'_'.time().'_'.$model->imgName->getName();
$model->setAttribute('imgName', $imgName_new);
$model->setAttribute('createdBy', Yii::app()->user->getId());
$model->setAttribute('createdAt', date('Y-m-d H:i:s'));
if($model->save()) {
$temp_img->saveAs($imgDir.'/'.$imgName_new);
// resizing options
Yii::import('application.extensions.image.Image');
$image = new Image($imgDir.'/'.$imgName_new);
CVarDumper::dump($image, 10, true);
$image->resize('400', '300');
$image->render();
// redirect to success page
$this->redirect(array('view','id'=>$model->id));
}
}
}
I also tried the 2nd usage example by using “$image = Yii::app()->image->load(‘pathToImg’); etc.” but I always receive a CException error:
. Even if I try to create an Image object with an invalid img src I got no error message that the image doesn’t exist as I should…
Every other extension works perfectly well.
Best wishes,
Sebastian