Skip to content

Instantly share code, notes, and snippets.

@Pierstoval
Created October 25, 2018 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pierstoval/d4acaed8e3caa4814b873644276aaaa3 to your computer and use it in GitHub Desktop.
Save Pierstoval/d4acaed8e3caa4814b873644276aaaa3 to your computer and use it in GitHub Desktop.
<?php
$h = fopen('php://memory', 'ab+');
$gd = @imagecreate(110, 20);
if (false === $gd) {
throw new \RuntimeException('GD image is invalid');
}
$background_color = imagecolorallocate($gd, 0, 0, 0);
$text_color = imagecolorallocate($gd, 233, 14, 91);
imagestring($gd, 1, 5, 5, 'A Simple Text String', $text_color);
imagepng($gd, $h);
rewind($h);
header('Content-Type: image/png');
$stdout = fopen('php://output', 'rb');
stream_copy_to_stream($h, $stdout);
fclose($stdout);
fclose($h);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment