astrotomic/laravel-imgix

Laravel 绑定和外观,用于生成 imgix URL 并支持多个来源。

1.2.0 2024-05-01 08:55 UTC

This package is auto-updated.

Last update: 2024-08-31 00:41:25 UTC


README

Latest Version MIT License Offset Earth Larabelles

GitHub Workflow Status StyleCI Total Downloads

Laravel 绑定和外观,用于生成 imgix URL 并支持多个来源。

安装

您可以通过 composer 安装此包。

composer require astrotomic/laravel-imgix

配置

首先,您需要通过 artisan 命令发布包配置文件。

php artisan vendor:publish --provider="Astrotomic\Imgix\ImgixServiceProvider" --tag="config"

之后,您将有一个 config/imgix.php 文件。其中的 default 键包含您想要默认使用的源名称。 sources 键包含一个以名称/标识符为键的源数组。

每个来源必须有一个 domain。其他键是可选的,您甚至可以省略它们。

return [
    'default' => 'default',

    'sources' => [
        'default' => [
            'domain' => 'example.imgix.net', // domain only - without http(s)
            // 'useHttps' => true, // default is true - you shouldn't change this
            // 'signKey' => null, // your signing key for this domain
            // 'includeLibraryParam' => true, // if you want to remove the `ixlib` param
        ],
        'astrotomic' => [
            'domain' => 'img.astrotomic.info',
            'useHttps' => true,
            'signKey' => 'mySecretSignKey',
            'includeLibraryParam' => false,
        ],
    ],
];

使用方法

此包提供了一个外观和全局函数,您可以使用它来获取预配置的 \Imgix\UrlBuilder

use Astrotomic\Imgix\Facades\Imgix;

Imgix::createURL('my/cool/image.jpg');
// https://example.imgix.net/my/cool/image.jpg?ixlib=php-3.3.0

Imgix::source('astrotomic')->createURL('logo.png');
// https://img.astrotomic.info/logo.png?s=200c1c2065023265285dcbc4eff99955

如果您不想导入外观,您可以使用全局函数,该函数是 Imgix::source() 方法的别名。

imgix()->createURL('my/cool/image.jpg');
// https://example.imgix.net/my/cool/image.jpg?ixlib=php-3.3.0

imgix('astrotomic')->createURL('logo.png');
// https://img.astrotomic.info/logo.png?s=200c1c2065023265285dcbc4eff99955

Blade 组件

此包包含一个名为 x-imgix 的 Blade 组件

<x-imgix path="my-image.png" class="img-class" alt="My fancy image" />

可选参数

  • source:使用在您的 imgix.php 配置中定义的一个源
  • width:定义输出宽度 - 将添加到参数中
  • height:定义输出高度 - 将添加到参数中
  • params:定义传递给 Imgix API 的参数数组

您可以通过运行以下命令发布视图:

php artisan vendor:publish --provider="Astrotomic\Imgix\ImgixServiceProvider" --tag="views"

测试

composer test

变更日志

有关最近更改的更多信息,请参阅 CHANGELOG

贡献

有关详细信息,请参阅 CONTRIBUTING。您也可能对 CODE_OF_CONDUCT 感兴趣。

安全

如果您发现任何安全问题,请参阅 SECURITY 了解报告步骤。

致谢

许可证

MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件

Treeware

您可以自由使用此包,但如果它进入您的生产环境,我将非常感谢您为世界购买一棵树。

众所周知,应对气候危机并防止气温上升超过 1.5C 的最佳工具之一是 植树。如果您为我的森林做出贡献,您将为当地家庭创造就业机会并恢复野生动物栖息地。

您可以在 offset.earth/treeware 购买树木。

了解更多关于 Treeware 的信息,请访问 treeware.earth