A convenient laravel facade which returns a placeholder image url.
- Installation
- Register Plugin (Laravel 5.5 and below)
- How to use
- Other image types
- A note about production envs
Install via composer
composer require kakposoe/laravel-placeholder-image
If you use Laravel < 5.5, Add service provider to config/app.php
in providers
section
Kakposoe\LaravelViewGenerator\LaravelViewGeneratorServiceProvider::class,
If you use Laravel < 5.5, register package facade in config/app.php
in aliases
section
Kakposoe\LaravelPlaceholderImage\Facades\LaravelPlaceholderImage::class,
php artisan vendor:publish --provider="Kakposoe\LaravelPlaceholderImage\ServiceProvider" --tag="config"
You can get a placeholder image url within your blade templates by adding:
{{ PlaceholderImage::get($width = null, $height = null) }}
By default, images will be returned as a 600px x 400px image.
To change the dimensions of the image, simply add the $width
and $height
like so:
{{ PlaceholderImage::get(300, 300) }}
There are several different types of image at your disposal:
To get a profile image placeholder:
<img src="{{ PlaceholderImage::profile($width = null, $height = null) }}">
You are able to create a placeholder image with a font-awesome icon in the middle:
<img src="{{ PlaceholderImage::icon('arrow-up') }}">
Note: By default, the fa-image
icon will be returned.
To return a blurry image:
<img src="{{ PlaceholderImage::blur($width = null, $height = null) }}">
You can return a placeholder url based on a keyword:
<img src="{{ PlaceholderImage::keyword('food') }}">
An placeholder image url which has the image dimensions can be returned using the ::dimensions()
method:
<img src="{{ PlaceholderImage::dimensions($width = null, $height = null) }}">
As these are placeholder images, it is assumed that these should not to be used within production environments.
All placeholder images used in production will be replaced with an ::icon()
placeholder image, avoiding showing inappropriate images and the impression that the image could not be found.