orzcc/image-laravel

Intervention Image 的 Laravel 集成

1.0 2024-07-03 03:26 UTC

This package is auto-updated.

Last update: 2024-09-03 03:52:14 UTC


README

Laravel 对 Intervention Image 的集成

Latest Version Tests Monthly Downloads

此包提供了一个简单的集成方法,将 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 目录。在此文件中,您可以设置所需驱动程序及其配置选项。默认情况下,库配置为使用 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 许可证 授权。