ilaoniu/dummyimage

v1.0.1 2025-01-27 07:16 UTC

This package is auto-updated.

Last update: 2025-03-27 07:40:53 UTC


README

Install

composer require ilaoniu/dummyimage --dev

Laravel

First, add a new route:

Route::middleware('cache.headers:public;max_age=2628000;etag')->get('__dummy-image/{size}/{bgColor?}/{textColor?}', function (Request $request, string $size, ?string $bgColor = null, ?string $textColor = null) {
    $dummyImage = new DummyImage;
    ['content' => $content, 'headers' => $headers] = $dummyImage->image($size, $bgColor, $textColor, $request->query('text'));

    return response($content)->withHeaders($headers);
});

Then, you can get image url like this:

$dummyImage = new DummyImage;
$dummyImage->imageUrl(config('app.url') . '/__dummy-image');

Usage

Size

width x height

Colors

background color / text color

Image Formats

.gif, .jpg, .png, .webp

  • Adding an image file extension will render the image in the proper format
  • Image format is optional and the default is a gif
  • jpg and jpeg are the same
  • The image extension can go at the end of size option in the url

Custom Text

?text=Hello+World

  • Custom text can be entered using a query string at the very end of the url
  • This is optional, default is the image dimensions (300×250)
  • a-z (upper and lowercase), numbers, and most symbols will work just fine.
  • Spaces become +

Thanks

https://github.com/kingkool68/dummyimage, Dummy Image is written in PHP and distributed freely under a MIT License.

Source code behind https://dummyimage.com