2016-05-23 25 views
0

我使用Intervention Image library在我Laravel 5.2的應用程序與Image Cache plugin如何創建和使用圖像模板與干預形象和Laravel 5.2

以來我一直在使用開箱預定義模板,象這樣沒有問題:

{{ route('imagecache', ['template' => 'medium', 'filename' => 'image.jpg']) }}" 

我已經看到,以及默認的尺寸小,中,大,你可以創建圖像過濾器來創建自定義操作,並定義它們作爲配置文件模板的文檔中,這樣,而不是媒體我會傳遞我的模板名稱。該文檔引用圖像過濾器作爲實現這一目的的一種方式,但對於如何做到這一點有點粗略。有誰知道你是如何做到的?

回答

2

裏面config/imagecache.php有一個templates關鍵,在這裏你可以添加你自己的。

例如:

'templates' => [ 
    // ... 
    'x-large' => 'App\Filters\ExtraLarge', 
    // ... 
], 

那麼你就只需要創建類App\Fitlers\ExtraLarge

applyFilter()方法中,您可以根據documentation調用$image屬性中的任何方法。

<?php 

namespace App\Filters; 

use Intervention\Image\Image; 
use Intervention\Image\Filters\FilterInterface; 

class ExtraLarge implements FilterInterface 
{ 
    public function applyFilter(Image $image) 
    { 
     return $image->fit(1300, 1000); 
    } 
} 

然後route幫手內模板的值設置爲x-large

{{ route('imagecache', ['template' => 'x-large', 'filename' => 'image.jpg']) }}