otisz/laravel-imgix

v3.2.0 2020-09-04 08:53 UTC

This package is auto-updated.

Last update: 2024-09-07 20:28:05 UTC


README

Latest Stable Version Build Status Total downloads Licence

Laravel 包,用于生成您图像的 Imgix URL。

依赖

安装

您可以通过 Composer 安装此包

$ composer require otisz/laravel-imgix

在 Laravel 5.5 或更高版本中,服务提供程序将自动注册。在框架的旧版本中,只需在 config/app.php 文件中添加服务提供程序即可

'providers' => [
    ...
    Otisz\Imgix\ImgixServiceProvider::class,
    ...
],

'aliases' => [
    ...
    'Imgix' =>  Otisz\Imgix\Facades\Imgix::class,
    ...
],

您可以使用以下命令发布配置文件

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

发布后,配置文件 config/imgix.php 包含

<?php

return [
    /*
    |--------------------------------------------------------------------------
    | ImgIX Domains
    |--------------------------------------------------------------------------
    |
    | Domain sharding enables you to spread image requests across
    | multiple domains. This allows you to bypass the requests-per-host
    | limits of browsers. We recommend 2-3 domain shards maximum if you are
    | going to use domain sharding.
    |
    | @link https://github.com/imgix/imgix-php#domain-sharded-urls
    |
    */
    'domain' => env('IMGIX_DOMAIN', 'example.imgix.net'),

    /*
    |--------------------------------------------------------------------------
    | ImgIX HTTPS
    |--------------------------------------------------------------------------
    |
    | For HTTPS support.
    |
    */
    'useHttps' => env('IMGIX_HTTPS', false),

    /*
    |--------------------------------------------------------------------------
    | ImgIX Signed URLs
    |--------------------------------------------------------------------------
    |
    | To produce a signed URL, you must enable secure URLs on your source
    | and then provide your signature key to the URL builder.
    |
    | @link https://github.com/imgix/imgix-php#signed-urls
    |
    */
    'signKey' => env('IMGIX_SIGNKEY', ''),

    /*
    |--------------------------------------------------------------------------
    | ImgIX Library Param
    |--------------------------------------------------------------------------
    |
    | For security and diagnostic purposes, we default to signing all requests
    | with the language and version of library used to generate the URL.
    |
    */
    'includeLibraryParam' => env('IMGIX_LIBRARY', true),
];

使用方法

更多关于 srcset 的信息。

$path:图像的路径
$params:由 Imgix 提供的参数

外观

\Imgix::createUrl('bridge.png', ['w' => 100, 'h' => 100]);

\Imgix::createSrcSet('bridge.png', ['w' => 100, 'h' => 100]);

助手

imgix('bridge.png', ['w' => 100, 'h' => 100])

imgixSrcSet('bridge.png', ['w' => 100, 'h' => 100])

测试

$ composer test

贡献

安全漏洞

如果您发现任何安全相关的问题,请通过电子邮件 leventeotta@gmail.com 联系我们,而不是使用问题跟踪器。所有安全漏洞都将得到及时处理。

许可证

Laravel Imgix 包是开源软件,受 MIT 许可证 许可。