Skip to content

Commit

Permalink
Fix deprecated method, empty buffer before output
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoverbruggen committed Aug 7, 2024
1 parent b3034de commit 2348205
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions examples/direct.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
targetSize: "200x200",
// Fun fact: if you set null for these, you'll get a random color for each generated placeholder!
// You can also specify a specific hex color. ("#EEE" or "#EEEEEE" are both accepted)
textColorHex: null,
backgroundColorHex: "#AFF"
textColorHex: "#333",
backgroundColorHex: "#AFB"
);

$generator->makePlaceholderImage("");
$generator->generate("");
14 changes: 7 additions & 7 deletions src/ImageGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(
* If null, won't render any text.
*
* @param null|string $path: The path where the image needs to be stored.
* If null, will directly output the image.
* If null, will directly output the image to the buffer.
*
* @param null|string $size: The target size of the image that will be rendered.
* For example: "100x100" is a valid size.
Expand Down Expand Up @@ -141,15 +141,15 @@ public function generate($text = "", $path = null, $size = null, $bgHex = null,
);
}

// Render image
if ($path == null) {
if ($path === null) {
ob_clean();
header('Content-type: image/png');
echo imagepng($imageResource, null);
exit;
} else {
imagepng($imageResource, $path);
return true;
}

imagepng($imageResource, $path);
return true;
}

/**
Expand All @@ -158,6 +158,6 @@ public function generate($text = "", $path = null, $size = null, $bgHex = null,
*/
public function makePlaceholderImage($text = "", $path = null, $size = null, $bgHex = null, $fgHex = null): bool
{
return $this->makePlaceholderImage($text, $path, $size, $bgHex, $fgHex);
return $this->generate($text, $path, $size, $bgHex, $fgHex);
}
}

0 comments on commit 2348205

Please sign in to comment.