2016-12-06 7 views
0

일부 지침 텍스트를 이미지로 변환하고 전자 메일로 보내야하는 프로젝트에서 작업하고 있습니다. 테스트 목적으로 텍스트를 이미지로 변환하면 작은 흰색 상자가 나타납니다. - ph

, 내가 출력 브라우저에 이미지로 변환 된 텍스트를 간단한 코드를 시도하고 있지만, 항상이 같은 작은 흰색 상자 반환 것 : enter image description here

내가 GD에 설치 한 내 섬기는 사람.

<?php 

header("Content-type: image/png"); 

function drawImage() 
{ 
    $width = 0; 
    $height = 0; 
    $offset_x = 0; 
    $offset_y = 0; 
    $bounds = array(); 
    $image = ""; 

    $msg = "Some Sample Text...."; 
    $font = "ARIAL.TTF"; 
    $size = 24; // default font size. 
    $rot = 0; // rotation in degrees. 
    $pad = 0; // padding. 
    $transparent = 1; // transparency set to on. 
    $red = 0; // black text... 
    $grn = 0; 
    $blu = 0; 
    $bg_red = 255; // on white background. 
    $bg_grn = 255; 
    $bg_blu = 255; 

    // get the font height. 
    $bounds = ImageTTFBBox($size, $rot, $font, "W"); 
    if ($rot < 0) 
    { 
     $font_height = abs($bounds[7]-$bounds[1]);  
    } 
    else if ($rot > 0) 
    { 
    $font_height = abs($bounds[1]-$bounds[7]); 
    } 
    else 
    { 
     $font_height = abs($bounds[7]-$bounds[1]); 
    } 
    // determine bounding box. 
    $bounds = ImageTTFBBox($size, $rot, $font, $msg); 
    if ($rot < 0) 
    { 
     $width = abs($bounds[4]-$bounds[0]); 
     $height = abs($bounds[3]-$bounds[7]); 
     $offset_y = $font_height; 
     $offset_x = 0; 
    } 
    else if ($rot > 0) 
    { 
     $width = abs($bounds[2]-$bounds[6]); 
     $height = abs($bounds[1]-$bounds[5]); 
     $offset_y = abs($bounds[7]-$bounds[5])+$font_height; 
     $offset_x = abs($bounds[0]-$bounds[6]); 
    } 
    else 
    { 
     $width = abs($bounds[4]-$bounds[6]); 
     $height = abs($bounds[7]-$bounds[1]); 
     $offset_y = $font_height;; 
     $offset_x = 0; 
    } 

    $image = imagecreate($width+($pad*2)+1,$height+($pad*2)+1); 
    $background = ImageColorAllocate($image, $bg_red, $bg_grn, $bg_blu); 
    $foreground = ImageColorAllocate($image, $red, $grn, $blu); 

    if ($transparent) ImageColorTransparent($image, $background); 
    ImageInterlace($image, false); 

    // render the image 
    ImageTTFText($image, $size, $rot, $offset_x+$pad, $offset_y+$pad, $foreground, $font, $msg); 

    // output PNG object. 
    imagePNG($image); 
} 
drawImage(); 
?> 

답변

1

변화 등이 간단하다 :

$image = imagereate 

나에게 오타 같은데

$image = imagecreate 

에 다음은 내 코드입니다.

+0

도움 주셔서 감사합니다. 실제로 그것은 원래 코드에서 올바르며, 나는 그 게시물을 수정했습니다. 죄송합니다. –