Bloodhound
Bloodhound

Reputation: 2966

How to resize an Image with copy Command

Is it possible to resize an image using copy command?

Below is my code

copy((Yii::getAlias('@api/web/uploads/users/'.$model->id."_".$model->image)),
                            (Yii::getAlias('@frontend/web/uploads/users/users_thumb/'.$model->id."_".$model->image))); 

which copies an image from users folder inside api to users_thumb folder in frontend. Can i any how resize the image that is getting stored in the user_thumb folder?

Upvotes: 0

Views: 253

Answers (1)

soju
soju

Reputation: 25322

You cannot use copy to resize an image, but you could simply use yii2-imagine extension, e.g. :

$src = Yii::getAlias("@api/web/uploads/users/{$model->id}_{$model->image}");
$dst = Yii::getAlias("@frontend/web/uploads/users/users_thumb/{$model->id}_{$model->image}";   
\yii\imagine\Image::thumbnail($src, 150, 150)->save($dst, ['quality' => 90]);

Or :

\yii\imagine\Image::getImagine()->open($src)
    ->thumbnail(new \Imagine\Image\Box(150, 150))
    ->save($dst, ['quality' => 90]);

Upvotes: 1

Related Questions