boomdraw / laravel-dummy-image
Laravel dummy image generator based on kingkool68/dummyimage
Installs: 1 557
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 2
Open Issues: 1
Requires
- php: ^7.0
- illuminate/support: ~5.5.0|~5.6.0|~5.7.0
Requires (Dev)
- orchestra/testbench: 3.5.*|3.6.*|3.7.*
- phpunit/phpunit: ^6.5|^7.0
This package is auto-updated.
Last update: 2024-12-06 01:14:41 UTC
README
This package allows you to generate dynamic dummy image in Laravel framework.
It's based on the Russell Heimlich's dummy image generator
Once installed you can do stuff like this:
// Generate and store an image DummyImage::put($path, $disk); // Generate and return image as response DummyImage::toResponse($code, $headers); // Generate and return image as base64 DummyImage::toBase64($code, $headers);
Installation
Laravel
You can install the package via composer:
composer require boomdraw/laravel-dummy-image
You can publish the config file with:
php artisan vendor:publish --provider="BoomDraw\DummyImage\DummyImageServiceProvider" --tag="config"
When published, the config/dummyimage.php
config file contains:
return [ /* * Default disk for generated image */ 'disk' => 'local', /* * Default path for generated image */ 'path' => 'dummyimage', /* * Additional headers for response */ 'headers' => [ // ], /* * Additional html color names with hex value for name to hex convertation */ 'color_names' => [ //'color_name' => '00ffff' ], ];
Usage
// Generate an image with custom params $image = DummyImage::generate($dimensions = '200x1:5', $format = 'gif', $bg_color = 'ff00cc', $fg_color = '00ffcc', $text = 'I am image text'); // Generate and store an image $image->put($path, $disk); // Generate and return image as response $image->toResponse($code, $headers); // Generate and return image as base64 string $image->toBase64($code, $headers);
If any of the methods will be used without generate() one, an image will be generated with default params.
You can provide your own parameters for generating image:
- $dimensions - image dimensions.
You can provide as dimensions image size and/or ratio. By default used '800x600'.
Examples:
'800x600' will generate an image with width 800px and height 600px
'800' will generate an image with 800px width and height
'250x1:2' will generate an image with 250px width and 500px height
'1:3x300' will generate an image with width 100px and height 300px - $format - generated image format ('jpg', 'gif', 'png'). Default format is 'png'.
- $bg-color - image background color in hex. Default is white ('ffffff').
- $fg_color - image text color in hex. Default is black ('000000').
- $text variable provides text that will be written on the image. Default is image dimensions.
Resources
License
The MIT License (MIT).
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.