flixtechs-labs / laravel-bytepoint
Bytepoint图像优化API客户端SDK,适用于laravel
0.0.3
2023-06-16 18:38 UTC
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.4
- illuminate/contracts: ^10.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.9
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
This package is auto-updated.
Last update: 2024-09-09 03:50:49 UTC
README
使用Bytepoint在Laravel中即时优化上传的图像。与现有工作流程完美契合
$file = $request->file('image'); $file->bytepoint([ 'type' => 'jpeg' ]) ->store('avatars');
安装
您可以通过composer安装此包
composer require flixtechs-labs/laravel-bytepoint
您可以使用以下命令发布配置文件
php artisan vendor:publish --tag="laravel-bytepoint-config"
这是发布配置文件的内容
return [ 'token' => env('BYTEPOINT_TOKEN', ''), 'url' => env('BYTEPOINT_URL', ''), ];
用法
要使用此包,您首先需要从Bytepont获取一个API令牌
访问https://bytepont.flixtechs.co.zw并创建一个帐户
在个人资料页面的底部点击“生成令牌”,并将令牌复制到您的.env文件中,如下所示
BYTEPOINT_TOKEN=XXXXXX
添加另一个可选的环境变量
BYTEPOINT_URL=https://bytepoint.flixtechs.co.zw/api/v1/images
在此之后,您只需要将bytepoint集成到现有的工作流程中。
此包向UploadedFile
对象添加了一个流畅的bytepoint()
辅助函数,它接受一个数组选项作为参数。
目前您只能指定输出文件类型,更多选项即将推出!
$request->file('image')->bytepoint(['type' => 'resulting type'])->store('avatars');
接受的文件类型列表
- webp
- png
- jpeg
在保存文件存储或任何其他媒体库之前调用bytepoint
优化现有图像
您还可以使用Bytepoint外观优化现有图像
use FlixtechsLabs\Bytepoint\Facades\Bytepoint; Bytepoint::optimize($filePath, $destinationPath, $fileName = '', $options = []);
参数如下
- 文件
$filePath
是要优化的文件的路径 $destinationPath
是保存优化文件的路径$fileName
是文件名,这是可选的$options
是一个选项数组,用于告诉bytepoint如何优化图像,目前您只能设置结果文件为webp,jpeg,png
测试
composer test
变更日志
有关最近更改的更多信息,请参阅CHANGELOG
贡献
有关详细信息,请参阅CONTRIBUTING
安全漏洞
有关报告安全漏洞的详细信息,请参阅我们的安全策略
致谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件