Re: imagettftext and utf-8 (swedish characters)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Nathan Rixham wrote:
David Sveningsson wrote:
Hi, I've ran into some problems when outputing text to an image using imagettftext. I cannot get swedish characters to work, I just get a square. I've tried different fonts which I know has those characters (bitstream vera, arial, times new roman, etc). What am I doing wrong?

I know I must pass utf-8 encoded text and I belive I do but I don't know how to check it.

HTML form code:
(html document uses utf-8 as charset and apache is set to use utf-8 too)

<form action="/index.php/slides/upload" method="post" accept-charset="utf-8">
<input type="text" id="title" name="title" size="70" value="" />
</form>

/index.php/slides/upload:

$title = htmlentities($_POST['title'], ENT_COMPAT, 'UTF-8');
$image = '/index.php/slides/preview?title='.urlencode($title).'&content='.urlencode($_POST['content']);

/index.php/slides/preview:

  function preview(){
    $title = html_entity_decode($_GET['title'], ENT_COMPAT, 'UTF-8');
    //$title = $_GET['title'];

    ///@note Hardcoded resolution
    $im  = imagecreatetruecolor(800, 600);
    $black  = imagecolorallocate($im, 0, 0, 0);
    $white  = imagecolorallocate($im, 255, 255, 255);
    $font = "/usr/share/fonts/corefonts/georgia.ttf";

    $title_size = 32;

    imagefilledrectangle($im, 0, 0, 800, 600, $black);

    imagettftext( $im, $title_size, 0, 50, 50, $white, $font, $title );
        header("Content-Type: image/png");
    imagepng($im);
    exit();
  }


try changing:
imagettftext( $im, $title_size, 0, 50, 50, $white, $font, $title );

to:
imagettftext($im, $title_size, 0, 50, 50, $white, $font, utf8_decode($title));

before going any further, your HTML page is in UTF-8 yes? with the appropriate content-type line.

plus: first debugging step:

function preview(){
$title = html_entity_decode($_GET['title'], ENT_COMPAT, 'UTF-8');
print_r($title); #verify in view source / web browser that data is correct before it's sent to imagettftext

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux