PHP

CONVERT TEXT TO IMAGE IN PHP

quick guide & example

IMAGE OBJECT $width = 150; $height = 80; $img = imagecreate($width, $height);

INITIALIZE & SETTINGS

01

SETTINGS $txt = "FOO BAR!"; $txtSize = 5; $txtX = 10; $txtY = 10; $red = imagecolorallocate($img, 255, 0, 0); $white = imagecolorallocate($img, 255, 255, 255);

DRAW BACKGROUND (RED RECTANGLE) imagefilledrectangle($img, 0, 0, $width, $height, $red);

DRAW TEXT TO IMAGE

02

WRITE TEXT imagestring($img, $txtSize, $txtX, $txtY, $txt, $white);

SAVE TO FILE imagepng($img, “IMAGE.png”);

OR DIRECT OUTPUT header("Content-type: image/png"); imagepng($img);

OUTPUT IMAGE

03