Introduce the extension for Yii 2

With Yii framework 2.0, I want to use the Imagine Extension for Yii 2. After the documentation, I first run the following command line.

php composer.phar require --prefer-dist yiisoft/yii2-imagine "*"

After running the above command line, I could see that the imag package appeared in the vendor directory. In my views of /site/index.php, I included the following code snippet.

use yii\imagine\Image;

// generate a thumbnail image
Image::thumbnail('@webroot/img/test-image.jpg', 120, 120)
->save(Yii::getAlias('@runtime/thumb-test-image.jpg'), ['quality' => 50]);

Below is the result:

 PNG  IHDRxx9d6   pHYs   + IDATx   y eW}  9w o o  ZJ  6  1`޺c  D n     L 8㈞G  c{     r ƀ$   R{UVV  [ {w?g x / ʪJUI ;      =  l       #.\     Bl'    @ ul  IL @)    - "MS< C   +    Z  븫0 R        Ã>   ?    q | ;ߡ n c v      a Dg4'IJ  W `   Įr  a} V ^) վ ~   l6{ |

No image. I do not know what I missed, the image path is correct. Does anyone know how to solve it? thank

+4
source share
3 answers

try it

Image::thumbnail(Yii::getAlias('@webroot').'/img/test-image.jpg', 120, 120)->save(Yii::getAlias('@runtime').'/thumb-test-image.jpg');
0
source

after installing the yii2-imagine package for composer sketching

php composer.phar --prefer-dist yiisoft/yii2-imagine

, , Yii:: $app- > basePath. "/web/img/testimg.jpg".

siteController.php

: yii\imagine\Image;

Image::thumbnail(Yii::$app->basePath."/web/img/testimg.jpg"., 120, 120)->save(Yii::$app->basePath."/web/img/thumb_testimg.jpg", ['quality' => 80]);
0

This is the right way to generate a thumb and relationship relationship:

use Imagine\Image\Box;
use yii\imagine\Image;

Image::getImagine()
                ->open($file)
                ->thumbnail(new Box($height, $width))
                ->save($file);
0
source

All Articles