kelvinakposoe / laravel-placeholder-image
Laravel 占位图图片
v1.0
2019-12-02 16:19 UTC
Requires
- php: >=7.0
- illuminate/support: 5.8.*|^6.0
Requires (Dev)
- orchestra/testbench: ~3.8.0
- phpunit/phpunit: ^7.0
This package is auto-updated.
Last update: 2024-09-06 03:28:44 UTC
README
一个方便的 Laravel Facade,可以返回占位图 URL。
安装
通过 composer 安装
composer require kakposoe/laravel-placeholder-image
注册服务提供者
如果你使用 Laravel < 5.5,将服务提供者添加到 config/app.php
文件的 providers
部分
Kakposoe\LaravelViewGenerator\LaravelViewGeneratorServiceProvider::class,
注册 Facade
如果你使用 Laravel < 5.5,在 config/app.php
文件的 aliases
部分注册包 Facade
Kakposoe\LaravelPlaceholderImage\Facades\LaravelPlaceholderImage::class,
发布配置文件
php artisan vendor:publish --provider="Kakposoe\LaravelPlaceholderImage\ServiceProvider" --tag="config"
如何使用
你可以在 blade 模板中通过添加以下代码来获取占位图 URL:
{{ PlaceholderImage::get($width = null, $height = null) }}
默认情况下,图片将返回为 600px x 400px 大小。
要更改图片的尺寸,只需添加 $width
和 $height
如下:
{{ PlaceholderImage::get(300, 300) }}
其他图片类型
你有多种不同的图片类型可供选择:
个人头像
获取个人头像占位图
<img src="{{ PlaceholderImage::profile($width = null, $height = null) }}">
图标图片
你可以创建一个带有中间字体图标占位图的图片
<img src="{{ PlaceholderImage::icon('arrow-up') }}">
注意: 默认情况下,将返回 fa-image
图标。
模糊图片
返回模糊图片
<img src="{{ PlaceholderImage::blur($width = null, $height = null) }}">
关键字搜索
你可以根据关键字返回一个占位图 URL
<img src="{{ PlaceholderImage::keyword('food') }}">
具有图片尺寸的占位图
可以使用 ::dimensions()
方法返回具有图片尺寸的占位图 URL
<img src="{{ PlaceholderImage::dimensions($width = null, $height = null) }}">
关于生产环境的说明
由于这些是占位图,假设它们不应在生产环境中使用。
所有在 production 中使用的占位图都将被替换为 ::icon()
占位图,以避免显示不适当的图片和无法找到图片的印象。