tvdr / picsum-placeholder
a simple way to use Picsum.photos in your Laravel app.
Requires
- php: ^7.4|^8.0
- illuminate/support: ^8.0
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2025-04-10 03:04:44 UTC
README
This package provides a simple way to use Picsum.photos in your Laravel app.
Installation
You can install the package via composer:
composer require tvdr/picsum-placeholder
Config Files
In order to edit the default configuration you may execute:
php artisan vendor:publish --provider="Tvdr\PicsumPlaceholder\PicsumPlaceholderServiceProvider" --tag="config"
After that, config/picsum-placeholder.php
will be created.
The configuration options are:
name | description | type | default value |
---|---|---|---|
api_url |
the base url for picsum.photos | string | https://picsum.photos/ |
width |
width of image | integer | 300 |
height |
height of image | integer | 300 |
blur |
amount of blur on image | false | integer[1..10] | false |
grayscale |
always get a grayscale image | false | true | false |
random |
append a random string to the url to bust browser cache | false | true | true |
override_route |
route to override (e.g to always load a placeholder on non existent storage images) | false | string | /storage/{path?} |
Usage
You can use the facade to write well-readable code as well as a predefined global helper method if you don't want it as a singleton
//return image url with default parameters PicsumPlaceholder::getUrl() picsum_placeholder()->getUrl()
//return image as a blob string with default parameters PicsumPlaceholder::getBlob() picsum_placeholder()->getBlob()
Use the methods below to set options
Width
PicsumPlaceholder::width(250); picsum_placeholder()->width(410);
Height
PicsumPlaceholder::height(120); picsum_placeholder()->height(540);
Blur
PicsumPlaceholder::blur(3); picsum_placeholder()->blur(false);
Grayscale
PicsumPlaceholder::grayscale(true); picsum_placeholder()->grayscale(false);
Random
PicsumPlaceholder::random(true); picsum_placeholder()->grayscale(false);
All methods are chainable so nothing stops you from using
PicsumPlaceholder::width(120)->height(500)->grayscale(false)->blur(2)->getUrl();
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email tiborbarta87@gmail.com instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.