From 5c84fe6ca1d1fa92b1008dc9687bf42110f61547 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Sun, 14 Mar 2021 23:39:20 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20Deprecate=20'makePlaceholderImag?= =?UTF-8?q?e'=20in=20favor=20of=20'generate'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 -- examples/saved.php | 17 ++++++++--------- src/ImageGenerator.php | 14 ++++++++++++-- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 2b78bb7..6ed6fc4 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/examples/saved.php b/examples/saved.php index af5a73d..55287e8 100644 --- a/examples/saved.php +++ b/examples/saved.php @@ -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" ); /* @@ -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" ); diff --git a/src/ImageGenerator.php b/src/ImageGenerator.php index 613d8d8..e48b576 100644 --- a/src/ImageGenerator.php +++ b/src/ImageGenerator.php @@ -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. @@ -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; @@ -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); + } }