Laravel 使用 Intervention/image 配置和修改驱动 imagick

时间:2020-01-09
本文章向大家介绍Laravel 使用 Intervention/image 配置和修改驱动 imagick,主要包括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

打开 config/app.php 文件

在 'providers' =>[...] 添加以下(容器服务注册)

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

 

修改驱动为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');
});

以上内容参考官网:http://image.intervention.io/getting_started/installation

原文地址:https://www.cnblogs.com/zjhblogs/p/12170594.html