Re: [PHP] imagettftext and utf-8 (swedish characters)
On Thu, Feb 28, 2008 at 8:45 PM, David Sveningsson [EMAIL PROTECTED] 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? Most likely, it's because the font doesn't have an entry for those characters. Try to find a TTF font that does have those entities and your problems will most likely be solved that easily. -- /Dan Daniel P. Brown Senior Unix Geek ? while(1) { $me = $mind--; sleep(86400); } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] imagettftext and utf-8 (swedish characters)
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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] imagettftext and utf-8 (swedish characters)
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
Re: [PHP] imagettftext and utf-8 (swedish characters)
Jochem Maas skrev: Jochem Maas schreef: 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(); It does sadly not work: *Warning*: imagettftext() [function.imagettftext http://83.209.20.148/function.imagettftext]: any2eucjp(): invalid code in input string in */home/ext/workspace/code/trunk/Projects/Slideshow/frontend/public/foo.php* on line *30 *If I suppress the warning I get an image with squares and random letters. Is something wrong with my php installation? linux-2.6.24-gentoo PHP 5.2.5-p20080206-pl3-gentoo Apache/2.2.8 './configure' '--prefix=/usr/lib64/php5' '--host=x86_64-pc-linux-gnu' '--mandir=/usr/lib64/php5/man' '--infodir=/usr/lib64/php5/info' '--sysconfdir=/etc' '--cache-file=./config.cache' '--with-libdir=lib64' '--enable-maintainer-zts' '--disable-cli' '--with-apxs2=/usr/sbin/apxs2' '--with-config-file-path=/etc/php/apache2-php5' '--with-config-file-scan-dir=/etc/php/apache2-php5/ext-active' '--without-pear' '--enable-bcmath' '--with-bz2' '--enable-calendar' '--with-curl' '--with-curlwrappers' '--disable-dbase' '--enable-exif' '--without-fbsql' '--without-fdftk' '--enable-ftp' '--with-gettext' '--with-gmp' '--with-kerberos=/usr' '--enable-mbstring' '--with-mcrypt' '--with-mhash' '--without-msql' '--without-mssql' '--with-ncurses' '--with-openssl' '--with-openssl-dir=/usr' '--enable-pcntl' '--without-pgsql' '--with-pspell' '--without-recode' '--disable-shmop' '--with-snmp' '--enable-soap' '--enable-sockets' '--without-sybase' '--without-sybase-ct' '--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm' '--with-tidy' '--disable-wddx' '--with-xmlrpc' '--with-xsl' '--enable-zip' '--with-zlib' '--disable-debug' '--enable-dba' '--with-cdb' '--with-db4' '--with-flatfile' '--with-gdbm' '--with-inifile' '--without-qdbm' '--with-freetype-dir=/usr' '--with-t1lib=/usr' '--enable-gd-jis-conv' '--with-jpeg-dir=/usr' '--with-png-dir=/usr' '--with-xpm-dir=/usr' '--with-gd' '--with-imap' '--with-imap-ssl' '--with-ldap' '--without-ldap-sasl' '--with-mysql=/usr' '--with-mysql-sock=/var/run/mysqld/mysqld.sock' '--without-mysqli' '--with-unixODBC=/usr' '--without-adabas' '--without-birdstep' '--without-dbmaker' '--without-empress' '--without-esoob' '--without-ibm-db2' '--without-iodbc' '--without-sapdb' '--without-solid' '--without-pdo-dblib' '--with-pdo-mysql=/usr' '--with-pdo-odbc=unixODBC,/usr' '--without-pdo-pgsql' '--with-pdo-sqlite=/usr' '--without-readline' '--with-libedit' '--without-mm' '--with-sqlite=/usr' '--enable-sqlite-utf8' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php