Re: imagettftext and utf-8 (swedish characters)
| From: | Nathan Rixham | Date: | Fri, 29 Feb 2008 02:06:27 +0000 |
| Subject: | Re: imagettftext and utf-8 (swedish characters) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-270675@lists.php.net to get a copy of this message | ||
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(){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));$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();}