Z
Z
ZaurK2016-11-19 18:55:40
Yii
ZaurK, 2016-11-19 18:55:40

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

Please tell me what is wrong here. I believe that he finds the file, but for some reason he cannot read it. Imagine installed and registered namespaces
Here is my action
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

1 answer(s)
Z
ZaurK, 2016-11-19
@ZaurK

Sorry for disturbing. I solved the problem by changing aliases.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question