본문으로 바로가기

[PHP] 글자를 이미지로 만들기

category 웹프로그래밍/PHP 2012. 4. 11. 14:29

<!--img.php-->

<html>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<body>

<img src="imgtest2.php?price=9000">

</body>

</html>

<!--끝-->



<!--imgtest2.php-->

<?php


header('Content-Type: image/png');


$im = imagecreatetruecolor(400, 30); // 이미지 사이즈 400*30

$white = imagecolorallocate($im, 255, 255, 255); // 흰색

$gray = imagecolorallocate($im, 128, 128, 128); // 회색

$black = imagecolorallocate($im, 0, 0, 0); // 검정색

imagefilledrectangle($im, 0, 0, 399, 29, $white); // 바탕색 흰색으로 채우기


$text = number_format($_GET["price"]); // 숫자에 , 찍어주기?

$font = 'ARIAL.TTF'; // 폰트 파일이 이 파일하고 같은 위치에 있어야 됨.

imagettftext($im, 20, 0, 11, 21, $gray, $font, $text); // 글씨쓰기 폰트사이트 20, 각도 0, X위치 11, Y위치 21

imagettftext($im, 20, 0, 10, 20, $black, $font, $text); // 글씨쓰기 폰트사이트 20, 각도 0, X위치 11, Y위치 21



imagepng($im);

imagedestroy($im);


?>

<!--끝-->


[출처] phpschool.com