yii2手動添加圖片處理外掛程式Imagine

來源:互聯網
上載者:User

yii2手動添加圖片處理外掛程式Imagine

1、首先從官網下載yii2-imagine的拓展

:https://github.com/yiisoft/yii2-imagine

下載包名稱:yii2-imagine-master

2、然後再下載imagine的外掛程式包

:https://github.com/avalanche123/Imagine/releases

下載完成之後請解壓

修改檔案夾名稱yii2-imagine-master為yii2-imagine

把這兩個檔案夾放到你的yii項目的vendor\yiisoft目錄裡

之後修改該目錄下的extensions.php檔案;

在後面添加代碼,目的是可以使用命名空間引入這個外掛程式:

  'yiisoft/yii2-imagine' =>   array (    'name' => 'yiisoft/yii2-imagine',    'version' => '2.0.3.0',    'alias' =>     array (      '@yii/imagine' => $vendorDir . '/yiisoft/yii2-imagine',    ),  ),  'yiisoft/Imagine' =>   array (    'name' => 'yiisoft/Imagine',    'version' => '7.0.0.0',    'alias' =>     array (      '@Imagine' => $vendorDir . '/yiisoft/Imagine/lib/Imagine',    ),  ),

然後在修改vendor\composer目錄下的autoload_psr4.php檔案;

在後面添加代碼:

'yii\\imagine\\' => array($vendorDir . '/yiisoft/yii2-imagine'),

到此,外掛程式添加成功了,接下來是使用;

1.直接在控制器引入外掛程式:

use yii\imagine\Image;

2使用方法:

//1.產生縮圖Image::thumbnail($filename, $width,$height,\Imagine\Image\ManipulatorInterface::THUMBNAIL_INSET)->save($savefilename, ['quality' => 100]);//產生新圖的品質 //參數說明:$filename 源檔案的路徑$savefilename 產生圖片後的儲存路徑$width 縮圖的寬$height 縮圖的高//預設是剪裁模式\Imagine\Image\ManipulatorInterface::THUMBNAIL_OUTBOUN 裁剪模式\Imagine\Image\ManipulatorInterface::THUMBNAIL_INSET 填充模式//2.剪裁圖片Image::crop($filename, $width,$height,[0,0])->save($savefilename, ['quality' => 100]);//產生新圖的品質  //參數說明:$filename 源檔案的路徑$savefilename 產生圖片後的儲存路徑$width 剪裁的寬$height 剪裁的高[0,0] 這個是剪裁的x,y點//3.添加浮水印Image::watermark($filename,$watermarkFilename,[0,0])->save($savefilename, ['quality' => 100]);//產生新圖的品質  //參數說明:$filename 源檔案的路徑$watermarkFilename 浮水印圖片[0,0] 這個是添加浮水印的x,y點

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.