soyumen-dey/laravel-image

为 Laravel 5.6 及以上版本提供编码和生成缩略图的包。

v1.0 2019-02-10 16:55 UTC

This package is not auto-updated.

Last update: 2024-10-02 03:56:21 UTC


README

Latest Version on Packagist Total Downloads

为 Laravel 5.6 及以上版本提供编码和存储上传图像的包。

安装

通过 Composer

此包依赖于 intervention/image

$ composer require soumen-dey/laravel-image

Laravel 自动发现将自动检测并添加包的服务提供者和别名。如果未检测到,请执行以下操作

$providers 数组中添加此包的服务提供者。

Soumen\Image\ImageServiceProvider::class

将此包的命名空间添加到 $aliases 数组中。

'Image' => Soumen\Image\Facades\Image::class

配置

默认情况下,此包使用 GD 库处理图像,要更改此行为以及修改默认存储选项,请发布此包的配置文件。

$ php artisan vendor:publish --provider="Soumen\Image\ImageServiceProvider"

用法

use Soumen\Image

$file = $request->file('file');

// This will initialize and extract meta-data from the image
$image = new Image($file);

// This will encode the image and generate thumbnail
$image->process();

// Store the image in the storage
$image->store();

您还可以使用方法链在一行中编写上述代码。

$image = (new Image($file))->process()->store();

您还可以指定参数。

$image = new Image($file);
$image->setQuality(90); // the jpeg image quality, default is 50
$image->setEncoding('png'); // default is jpeg
$image->setStorage('images'); // set the storage
$image->generateThumbnail(); // generates the thumbnail
$image->encode();
$image->store();

如果您想指定参数,请勿使用 $image->process()

您还可以在上述代码上使用方法链。

变更日志

有关最近更改的更多信息,请参阅变更日志

贡献

有关详细信息以及待办事项列表,请参阅 contributing.md

安全

如果您发现任何安全相关问题,请通过作者邮箱联系,而不是使用问题跟踪器。

鸣谢

许可证

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