Laravel 使用 Intervention/image 配置和修改驅動 imagick


基本環境要求

環境需求:

  • PHP >= 5.4
  • Fileinfo Extension
  • Laravel >=5.0

拓展包需求:

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

安裝

前提:你已經安裝好laravel 項目,且當前在項目目錄

comoposer 安裝 intervention/image

php composer.phar require intervention/image

在Laravel 中注冊 intervention/image

1.打開 config/app.php 文件 

2.在 'providers' =>[...] 添加以下(容器服務注冊)

Intervention\Image\ImageServiceProvider::class
3.在 'aliases' =>[...] 添加以下(門面注冊:[可以直接使用Image::make()])
'Image' => Intervention\Image\Facades\Image::class

 4.enjoy!

修改驅動為imagick (默認為GD驅動--可以不做配置)

執行命令:

php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravelRecent"

這時你的config目錄下會多出一個image.php 

將 'driver' => 'gd' 改為  'driver' => 'imagick' 即可

文件如下:

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Image Driver
    |--------------------------------------------------------------------------
    |
    | Intervention Image supports "GD Library" and "Imagick" to process images
    | internally. You may choose one of them according to your PHP
    | configuration. By default PHP's "GD Library" implementation is used.
    |
    | Supported: "gd", "imagick"
    |
    */

    'driver' => 'imagick'

];

 

使用范例:

// usage inside a laravel route
Route::get('/', function()
{
    $img = Image::make('foo.jpg')->resize(300, 200);

    return $img->response('jpg');
});

 

 

 

以上內容參考 Intervention/image 官網:http://image.intervention.io/getting_started/installation


免責聲明!

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



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