shawnsandy / img-fly
动态在线调整图像大小
v0.1.21
2018-01-24 15:31 UTC
Requires
- php: >=7.0
- illuminate/support: 5.*
- league/glide-laravel: 1.*
Requires (Dev)
- phpstan/phpstan: ^0.9.0
This package is not auto-updated.
Last update: 2024-09-15 05:02:29 UTC
README
Laravel ImgFly
使用来自 thephpleague 的 Glide 库,在 Laravel 应用中动态在线调整图像大小。
Glide 是一个用 PHP 编写的简单易用的按需图像处理库。它的简单 API 通过 HTTP 提供访问,类似于 Imgix 和 Cloudinary 这样的云图像处理服务。Glide 利用像 Intervention Image(用于图像处理和调整)和 Flysystem(用于文件系统抽象)这样的强大库。
- 使用简单的基于 HTTP 的 API 调整、调整大小和添加图像效果。
- 处理后的图像将自动缓存,并带有未来的过期头提供。
- 创建自己的图像处理服务器或直接将 Glide 集成到您的应用中。
- 支持 GD 库和 Imagick PHP 扩展。
- 支持许多响应方法,包括 PSR-7、HttpFoundation 等。
- 可以使用 HTTP 签名来安全地保护图像 URL。
- 由于 Flysystem 库,可与许多不同的文件系统一起工作。
- 由经过实战考验的 Intervention Image 图像处理和调整库提供支持。
- 框架无关,可与任何项目一起使用。
- Composer 准备就绪并符合 PSR-2。
- 获取更多信息 - glide.thephpleague.com
安装 Glide Laravel
通过 composer 仓库
- 使用 composer 仓库安装包,请将以下内容添加到您的
composer.json
文件中
"repositories": [
{
"type": "vcs",
"url": "https://github.com/shawnsandy/img-fly"
}
],
- 运行 composer require 来安装包
composer require shawnsandy/img-fly
在 Laravel 5.5 及更高版本中,包会自动安装。如果您正在运行 Laravel 5.4 或更早版本,请按照以下说明操作。
- 将提供者添加到您的
config\app.php
提供者。
ShawnSandy\ImgFly\ImgflyServiceProvider::class,
- 将外观添加到您的
config\app.php
别名。
"Imgfly" => ShawnSandy\ImgFly\Classes\ImgflyFacade::class,
路由
- 将路由添加到您的
routes\web.php
Imgfly::routes();
依赖项(必需)
- 安装 php league Laravel glide 包 信息和说明
composer require league/glide-laravel
用法
- 从您的存储文件夹
storage/app/images
目录显示并调整图像大小w=500
将图像宽度设置为500
。
<img src="{{ Imgfly::imgFly('apple-mouse.jpeg?w=500') }}" alt="">
- 从您的
public/img
目录显示并调整图像大小w=500
将图像宽度参数设置为500
。有关设置其他参数(高度、裁剪、方向)的更多信息,请参阅 Glide 快速参考。
<img src="{{ Imgfly::imgPublic('hands.jpeg?w=500', 'img') }}" alt="">
预设
您还可以使用预设动态在线调整图像大小。参数设置在配置 app/imgfly.php
中。
- 发布配置文件
php artisan vendor:publish --tag=imgfly_config
- 打开并修改预设
[ "icon" => "?w=60&h=60&fit=crop-center", "small" => "?w=100&h=100&fit=crop-center", "thumbnail" => "?w=200&h=200&fit=crop-center", "medium" => "?w=600&h=400&fit=crop-center", "large" => "?w=1200&h=600&fit=crop-center", ];
- 调用外观
Imgfly::imgPreset(image, preset_key = small, callBackMethod = 'img/imgPublic')
<img src="{{ Imgfly::imgPreset('hands.jpg', 'icon') }}" alt=""> <img src="{{ Imgfly::imgPreset('hands.jpg', 'small') }}" alt=""> <img src="{{ Imgfly::imgPreset('hands.jpg', 'thumbnail') }}" alt="">
测试
$ composer test
贡献
有关详细信息,请参阅 CONTRIBUTING 和 CONDUCT。
安全
如果您发现任何与安全相关的问题,请通过电子邮件 shawnsandy04@gmail.com 而不是使用问题跟踪器。
鸣谢
- [Shawn Sandy][link-author]
待办事项
- 添加图像上传 UI
- 添加单元测试