le0daniel/laravel-image-engine

自动图像处理和服务的集成

v2.3.0 2020-07-13 10:53 UTC

This package is auto-updated.

Last update: 2024-09-13 21:02:16 UTC


README

Tests

为Laravel提供的强大图像引擎。不要浪费时间去编写调整和转换图像的逻辑。

安装

composer require le0daniel/laravel-image-engine

之后,使用以下命令发布配置文件:

artisan vendor:publish

配置

在配置文件中配置应用程序应提供的所需文件大小。

确保在image-engine.php配置文件中所有必要的路径都存在。

使用方法

图像引擎基于ImageRepresentation类。

use Carbon\Carbon;use le0daniel\Laravel\ImageEngine\Image\ImageRepresentation;

$image = ImageRepresentation::from(
    'file/path/relative/to/disk',
    'medium', // Desired image size defined in config
    null,     // Expire Timestamp or Carbon
    'local'   // name of the storage disk where the image is located
);

$imgUrl = image_url($image, 'png' /* Desired output format: jpg | png */);

这将为您生成一个签名的图像URL。图像仅在首次请求此URL时进行转换。图像将通过Intervention Image转换为指定的格式。

为了更好的性能,图像存储在公共文件夹中。这允许nginx在文件生成后提供服务。如果图像有有效期,图像将存储在配置中定义的路径。在这种情况下,即使图像已被缓存,php也将提供图像。

如果您需要用于本地处理的文件(例如:发送电子邮件),只需使用

image_real_path($image, 'png');

这将为您返回转换后图像的本地路径。