Create a true color image in PHP – command line example (imagecreatetruecolor)

0

Original code (works in web server):

<?php
header ('Content-Type: image/png');
$im = @imagecreatetruecolor(120, 20)
      or die('Cannot Initialize new GD image stream');
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  'A Simple Text String', $text_color);
imagepng($im);
imagedestroy($im);
?>

Modified code (works in command line):

<?php
$im = @imagecreatetruecolor(120, 20)
      or die('Cannot Initialize new GD image stream');
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  'A Simple Text String', $text_color);
imagepng($im, "x.png");
imagedestroy($im);
?>

Credits:
Some snippets adapted from documentation
provided by The PHP Documentation Group.

The PHP manual text and comments
are covered by the Creative Commons Attribution 3.0 License,
copyright (c) the PHP Documentation Group.
https://www.php.net/manual/en/cc.license.php
https://www.php.net/manual/en/copyright.php

The original snippet is here:
https://www.php.net/manual/en/function.imagecreatetruecolor.php

Subcribe now to LUNLUN.com newsletter and you will get the cheatsheet "Top 10 Trigonometry Formulas" as a gift.
It is free to subscribe.
You may unsubscribe at any time.
The privacy policy is here
.

Your email address:



0