PHP

HOW TO CONVERT TEXT TO IMAGE IN PHP

imagecreate(WIDTH, HEIGHT)  $img = imagecreate(500, 300);

imagecolorallocate(IMAGE, RED, GREEN, BLUE)  $black = imagecolorallocate($img, 0, 0, 0); $white = imagecolorallocate($img, 255, 255, 255);

EMPTY CANVAS & COLORS

01

imagefilledrectangle(IMAGE, X, Y, WIDTH, HEIGHT, COLOR) imagefilledrectangle($img, 0, 0, 500, 300, $white);

imagestring(IMAGE, FONT, X, Y, TEXT, COLOR) imagestring($img, 5, 0, 0, “TEXT”, $black);

BACKGROUND & TEXT

02

Save to file - imagepng(IMAGE, FILE); imagepng($img, “IMAGE.png”);

Direct Output header('Content-type: image/png'); imagepng($img);

OUTPUT IMAGE

03