Skip to content

Commit

Permalink
👌 Deprecate 'makePlaceholderImage' in favor of 'generate'
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoverbruggen committed Mar 14, 2021
1 parent e9e9e5c commit 5c84fe6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

This package is intended to be used for quickly generating placeholder images with a specific size, color and text.

Now that PHP 8.0 supports named arguments, I've updated this package.

## Requirements

* PHP 8.0 or higher
Expand Down
17 changes: 8 additions & 9 deletions examples/saved.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@

// Let's use a barebones generator first
$generator = new ImageGenerator();
$generator->makePlaceholderImage(
"",
__DIR__ . "/image_example_barebones.png"
$generator->generate(
path: __DIR__ . "/image_example_barebones.png"
);

/*
Expand All @@ -43,15 +42,15 @@
);

// We'll do a multiline message here
$generator->makePlaceholderImage(
"My\nname\nis\nBond.", // The text that will be added to the image
__DIR__ . "/image_example.png" // The path where the image will be saved
$generator->generate(
text: "My\nname\nis\nBond.", // The text that will be added to the image
path: __DIR__ . "/image_example.png" // The path where the image will be saved
);

// Generate a makePlaceholderImage image, for example for an avatar with initials
// We'll increase the font size first!
$generator->fontSize = 90;
$generator->makePlaceholderImage(
"NV",
__DIR__ . "/image_example_avatar.png"
$generator->generate(
text: "NV",
path: __DIR__ . "/image_example_avatar.png"
);
14 changes: 12 additions & 2 deletions src/ImageGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public function __construct(
) {}

/**
* Render or save a placeholder image. (Will always be a PNG.)
* Generates an image; directly renders or saves a placeholder image.
* This will always be PNG.
*
* @param string $text: The text that should be rendered on the placeholder.
* If left empty (""), will render the default size of the image.
Expand All @@ -49,7 +50,7 @@ public function __construct(
*
* @return bool
*/
public function makePlaceholderImage($text = "", $path = null, $size = null, $bgHex = null, $fgHex = null)
public function generate($text = "", $path = null, $size = null, $bgHex = null, $fgHex = null): bool
{
// The target size is either the one set in the class or the override
$targetSize = empty($size) ? $this->targetSize : $size;
Expand Down Expand Up @@ -150,4 +151,13 @@ public function makePlaceholderImage($text = "", $path = null, $size = null, $bg
return true;
}
}

/**
* @deprecated: Use `generate` instead.
* @return bool
*/
public function makePlaceholderImage($text = "", $path = null, $size = null, $bgHex = null, $fgHex = null): bool
{
return $this->makePlaceholderImage($text, $path, $size, $bgHex, $fgHex);
}
}

0 comments on commit 5c84fe6

Please sign in to comment.