Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Images in PHP [closed]

Tags:

php

image

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?

like image 433
Teifion Avatar asked Aug 24 '08 16:08

Teifion


People also ask

Can we do images using PHP?

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.

How do I check if an image is valid in PHP?

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.


2 Answers

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:

imagecreatetrucolor example
(source: php.net)

See imagecreatetruecolor.

like image 176
Ross Avatar answered Oct 20 '22 21:10

Ross


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.

like image 25
Konrad Rudolph Avatar answered Oct 20 '22 20:10

Konrad Rudolph