사이트 내 전체검색
PHP
텍스트를 이미지로 변환하는 간단소스(한글지원)
로빈아빠
https://cmd.kr/php/337 URL이 복사되었습니다.

본문

function textToImage($text, $fname, $fsize) {
    $text = iconv("EUC-KR", "UTF-8", $text); // 한글지원
    $padding = 10; // 이미지여백
    $ttf  ="폰트가 있는 서버경로";
    $size = imagettfbbox($fsize, 0, $ttf, $text);
    $xsize = abs($size[0]) + abs($size[2])+($padding*2);
    $ysize = abs($size[5]) + abs($size[1])+($padding*2);
    $image = imagecreate($xsize, $ysize);
    $bcolor = imagecolorallocate ($image, 255, 255, 255);
    $fcolor = imagecolorallocate ($image, 255, 0, 0);
    imagefilledrectangle($image, 0, 0, $xsize, $ysize, $bcolor);
    imagettftext($image, $fsize, 0, $padding, $fsize+$padding, $fcolor, $ttf, $text);
    imagejpeg($image,$fname, 85);
    imagepng($image);
    imagedestroy($image);
}

textToImage("한글 English 특수문자 ♥","title1.jpg","25");
echo "<img src='title1.jpg'>";

댓글목록

등록된 댓글이 없습니다.

PHP
871 (1/18P)

Search

Copyright © Cmd 명령어 18.117.186.92