Re: imagettftext and utf-8 (swedish characters)

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

 



Jochem Maas schreef:
David Sveningsson schreef:
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();
  }

have you tried a test script (file encoded as UTF8) where you hardcode the
title string and see if that also outputs 'squares' ... at least that way
you can be sure whether the problem is in some kind of encoding mush that occurs during the title's roundtrip of server -> browser -> server OR whether the problem is
actually to do with imagetfftext.

I tried in on my local machine (php5.2.5) and I can output swedish characters
no problem (I hope the below test script comes through with borking the
UTF-8 chars)

<?php

set_time_limit(0);

//$title = html_entity_decode($_GET['title'], ENT_COMPAT, 'UTF-8');
//$title = 'åååååååå bork';
//$title = 'Pippi Långstrump går om bord';
/*
$title = 'Alla människor är födda fria
och lika i värde och rättigheter.
De är utrustade med förnuft och
samvete och bör handla gentemot
varandra i en anda av broderskap.';
//*/
$title = 'hå kå  Å å Ä ä Ö ö å ö';

///@note Hardcoded resolution
$im     = imagecreatetruecolor(400, 200);
$black  = imagecolorallocate($im, 0, 0, 0);
$white  = imagecolorallocate($im, 255, 255, 255);
//$font   = "/Applications/OpenOffice.org 2.3.app/Contents/share/fonts/truetype/Georgia.ttf";
$font   = "/Library/Fonts/Georgia.ttf";

$title_size = 18;

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

imagettftext( $im, $title_size, 0, 20, 40, $white, $font, $title );

header("Content-Type: image/png");
imagepng($im);
exit();






--
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