intervention/image-laravel

Laravel 的 Intervention Image 集成

1.3.0 2024-06-15 08:20 UTC

This package is auto-updated.

Last update: 2024-09-21 07:55:31 UTC


README

Laravel 集成 Intervention Image

Latest Version Tests Monthly Downloads Support me on Ko-fi

此包提供了一个简单的集成,将Intervention Image集成到您的Laravel应用程序中。包括Laravel服务提供程序、外观和可发布的配置文件。

需求

  • Laravel >= 8

安装

在您现有的Laravel应用程序中,您可以使用Composer安装此包。

composer require intervention/image-laravel

接下来,使用vendor:publish命令将配置文件添加到您的应用程序中

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

此命令将发布图像集成配置文件image.php到您的app/config目录。在此文件中,您可以设置Intervention Image所需驱动及其配置选项。默认情况下,库配置为使用GD库进行图像处理。

配置文件如下。

return [

    /*
    |--------------------------------------------------------------------------
    | Image Driver
    |--------------------------------------------------------------------------
    |
    | Intervention Image supports “GD Library” and “Imagick” to process images
    | internally. Depending on your PHP setup, you can choose one of them.
    |
    | Included options:
    |   - \Intervention\Image\Drivers\Gd\Driver::class
    |   - \Intervention\Image\Drivers\Imagick\Driver::class
    |
    */

    'driver' => \Intervention\Image\Drivers\Gd\Driver::class,

    /*
    |--------------------------------------------------------------------------
    | Configuration Options
    |--------------------------------------------------------------------------
    |
    | These options control the behavior of Intervention Image.
    |
    | - "autoOrientation" controls whether an imported image should be
    |    automatically rotated according to any existing Exif data.
    |
    | - "decodeAnimation" decides whether a possibly animated image is
    |    decoded as such or whether the animation is discarded.
    |
    | - "blendingColor" Defines the default blending color.
    */

    'options' => [
        'autoOrientation' => true,
        'decodeAnimation' => true,
        'blendingColor' => 'ffffff',
    ]
];

您可以在驱动选择、设置自动方向解码动画混合颜色的不同选项中了解更多信息。

入门

集成现在已完成,您可以通过Laravel的外观系统访问ImageManager

use Intervention\Image\Laravel\Facades\Image;

Route::get('/', function () {
    $image = Image::read('images/example.jpg');
});

请阅读Intervention Image官方文档以获取更多信息。

作者

此库由Oliver Vogel开发和维护。

感谢贡献者社区,他们帮助改进了这个项目。

许可

Intervention Image Laravel根据MIT许可证许可。