Is it possible to create images with PHP (as opposed to simply linking to them via HTML) and if so, where should I go first to learn about such a thing?
PHP is not limited to creating just HTML output. It can also be used to create and manipulate image files in a variety of different image formats, including GIF , PNG , JPEG , WBMP , and XPM . Even more conveniently, PHP can output image streams directly to a browser.
In first method we have one built in function in PHP named as getimagesize(). Bu using this function we can check whether the image is valid or fake image file. In second method is done by curling the link or CURL, we can achieve this.
I prefer the GD library - check out the Examples, and this example:
<?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);
?>
Outputs:
(source: php.net)
See imagecreatetruecolor.
Yes this is possible. I believe there are multiple libraries to accomplish this. The most widely used is probably ImageMagick which is actually not PHP specific but comes with appropriate bindings.
See also in the PHP documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With