在 Laravel 中使用圖片處理庫 Integration/Image


系統需求

  •  PHP >= 5.3
  •  Fileinfo Extension
  •  GD Library (>=2.0) … or …
  •  Imagick PHP extension (>=6.5.7)


安裝部署 Integration/image
在 composer.json [require] 節增加,之后執行 composer update

"intervention/image": "2.0.15"

 

Laravel 配置

安裝部署 Integration/image 完成后,打開配置文件 config/app.php 在相應位置添加代碼,然后 Image 類就能自動加載並可供使用了。其功能強大到可以處理你的幾乎所有圖片處理需求。

//服務提供器
'Intervention\Image\ImageServiceProvider'

//別名配置
'Image' => 'Intervention\Image\Facades\Image'

 

配置設置
默認情況下, Integration/Image 使用PHP的GD庫擴展。如果你想切換到 imagick,你可以使用 php artisan 創建一個配置文件以添加相應的配置。

$ php artisan config:publish intervention/imag

 

基本使用

這里列出幾個基本功能,更詳細使用說明請查看相關接口文檔。
1、顯示一張圖片

Route::get('/', function()
{
       $img = Image::make('foo.jpg')->resize(300, 200);
       return $img->response('jpg');
});

 

2、讀取一個圖片文件

$img = Image::make('foo/bar/baz.jpg');

 

3、繪制一張圖片

$img = Image::canvas(800, 600, '#ccc');

 

4、編輯一張圖片

$img = Image::make('foo.jpg')->resize(320, 240)->insert('watermark.png');

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM