Answer the question
In order to leave comments, you need to log in
What's wrong with resizing an image?
Hello! I upload the photo to a folder and put it in the database, everything works fine, but I decided to resize and put the thumbnail in a separate folder and an error is displayed that the file cannot be read.
Imagine\Exception\RuntimeException
Unable to open image http://alf.loc/uploads/images/61510.jpg
↵
Caused by: ImagickException
Failed to read the file
public function actionCreate()
{
$model = new Good();
if ($model->load(Yii::$app->request->post())) {
//get the instance of uploaded file
$imageName = rand(1000,100000);
$model->file = UploadedFile::getInstance($model, 'file');
//saving
$model->image = $imageName.'.'.$model->file->extension;
$model->save();
$model->file->saveAs(Yii::getAlias('@frontend/web/uploads/images/' . $imageName. '.' .$model->file->extension));
//saving thumbnail
$dirfrom = Yii::getAlias('@frontendWebroot/uploads/images/');
$dirto = Yii::getAlias('@frontendWebroot/uploads/thumbnails/');
$imagine = new Image;
$size = new Box(40, 40);
Image::getImagine()->open($dirfrom . $imageName. '.' .$model->file->extension)
->thumbnail($size)
->save($dirto . $imageName.'.'.$model->file->extension, ['quality' => 90]);
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question