문제

I use this script to make html code into image using php-gd library:

<?php
    //put your html code here 
    $html_code = ' 
    <html> 
        <body> 
            Image Out Put sadadasdasdasdasdasd
        </body> 
    </html>
    '; 

    $img = imagecreate("300", "600"); 
    imagecolorallocate($img,0,0,0); 
    $c2 = imagecolorallocate($img,70,70,70); 
    imageline($img,0,0,300,600,$c2); 
    imageline($img,300,0,0,600,$c2); 

    $white = imagecolorallocate($img, 255, 255, 255); 
    imagettftext($img, 9, 0, 1, 1, $white, "arial.ttf", $html_code); 

    header('Content-type: image/jpeg'); 
    imagejpeg($img); 

?>

site url:

http://almogas.com/temp/phpimage.php?id=3

I get lot of unknown characters. How can I fix this behavior?

///////////////////////////////////////////////

edit

now its working after delete the spaces

but there is way to add background image? thank you

도움이 되었습니까?

해결책

You have unwanted chars before <?. remove all blank lines and spaces before <? your image is otherwise correct.

<? must be the first character first line in your script. you can avoid ?> if you use it it must be the last line last chars.

다른 팁

Please make sure that your file start without spaces or extra chars. It is important that it starts with

<?

You can avoid the closing

?>

So that you're sure to not send any other unwanted output to the client.

  • Make sure you have the GD library enabled on your server.
  • You should use png instead of jpg as png produces better text quality
  • You should use imagedestroy after imagejpeg or imagepng to clean up memory
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top