Re: [PHP] Re: imagettftext and utf-8 (swedish characters)
At 8:35 AM +0100 3/6/08, David Sveningsson wrote: Sidenote: If I replace åäö with numerical html entities it works, but that's not a reasonable solution to me. And you're right -- it isn't a reasonable solution . Whatever is generating your characters should generating the same characters regardless. However, some word processing programs, like Word for example, make substitutions to those characters that look fine when reviewing the documents in Word, but when viewed by other programs don't look right. One of the most obvious and common ones for me is reviewing things like this: think thats another case I see this all the time in email where people use some key combination to produce an apostrophe when it translates to a comma. It would be nice if our applications would not make substitutions for us. This is similar to the PUNYCODE mess that some browsers make of IDNS. Only three percent of the Global population use English as their native language. The rest of the world wants on the Internet and wants to be able to use their own language. But some Browser developers (i.e., IE) don't want other-than-English characters to be shows in urls but instead show PUNYCODE, which was never designed to be viewed by the end user. Arrogance and ignorance are often coupled. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: imagettftext and utf-8 (swedish characters)
tedd skrev: At 2:17 AM + 2/29/08, Nathan Rixham wrote: Nathan Rixham wrote: 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)); Both statements work for me. -- see here: http://www.webbytedd.com/b1/special-char/ But I don't know -- it looks Swedish to me. :-) Cheers, tedd I've started thinking something is wrong with my php installation as it seems to work for everyone else. Wrote more details in an earlier mail. Sidenote: If I replace åäö with numerical html entities it works, but that's not a reasonable solution to me. -- //*David Sveningsson [eXt]* Freelance coder | Game Development Student http://sidvind.com Thou shalt make thy program's purpose and structure clear to thy fellow man by using the One True Brace Style, even if thou likest it not, for thy creativity is better used in solving problems than in creating beautiful new impediments to understanding. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: imagettftext and utf-8 (swedish characters)
At 2:17 AM + 2/29/08, Nathan Rixham wrote: Nathan Rixham wrote: 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)); Both statements work for me. -- see here: http://www.webbytedd.com/b1/special-char/ But I don't know -- it looks Swedish to me. :-) Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: imagettftext and utf-8 (swedish characters)
Jochem Maas skrev: I guess I skimmed somewhat too ... but I based my assumption on the following from the OPs post: /index.php/slides/upload: $title = htmlentities($_POST['title'], ENT_COMPAT, 'UTF-8'); $image = '/index.php/slides/preview?title='.urlencode($title).'&content='.urlencode($_POST['content']); so the script handle the form submission looks to be generating a url used as the src of an img. Yes, the script generates an url to the script that renders the image. $image is later used in an img-tag. Maybe there is another way to solve this but this was the only thing I could think of. I have noted that if I use numerical html entities for åäö (Å for instance) I can see the characters correctly. I guess that would mean the string passed is *not* correct utf-8. Here is the current source: $title = htmlentities( stripslashes($_POST['title']), ENT_NOQUOTES, "utf-8" ); $content = htmlentities( stripslashes($_POST['content']), ENT_NOQUOTES, "utf-8" ); $image = '/index.php/slides/preview?title='.urlencode($title).'&content='.urlencode($content)."&align=$align"; ... $title = html_entity_decode(get('title'), ENT_NOQUOTES, 'UTF-8'); $im = imagecreatetruecolor(800, 600); $black = imagecolorallocate($im, 0, 0, 0); $white = imagecolorallocate($im, 255, 255, 255); //$font = "/usr/share/fonts/corefonts/arial.ttf"; $font = "/usr/share/fonts/ttf-bitstream-vera/Vera.ttf"; $title_size = 42; imagefilledrectangle($im, 0, 0, 800, 600, $black); $this->_string_centered($im, 70, $title_size, $font, $white, $title); header("Content-Type: image/png"); imagepng($im); Thus, it leads me back to my previous guess that the font he chose (georgia.ttf) doesn't have Swedish characters in the set. With that, I'm not sure, though, because I don't have the Georgia font pack on here, so it'll have to stay as a guess for now. Georgia.tff should cover swedish characters - atleast it does on my system (MPB) ... my little test script in my other post on this thread works for me ... I have no idea if one should/could expect variations of supported characters in a TTF font file depending on the system your on (my guess would be you could rely on all systems that have said TTF file to support the same chars - I assume that although it may be compiled diffferently for different platforms the source font definition is going to be the same) All fonts I have tried works in other applications with utf-8. (I run lamp on my own workstation at the moment). If anyone want to see the site or complete source I could send the url off-list. //*David Sveningsson [eXt]* Freelance coder | Game Development Student http://sidvind.com Thou shalt make thy program's purpose and structure clear to thy fellow man by using the One True Brace Style, even if thou likest it not, for thy creativity is better used in solving problems than in creating beautiful new impediments to understanding. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: imagettftext and utf-8 (swedish characters)
Frank Arensmeier skrev: 29 feb 2008 kl. 03.41 skrev David Sveningsson: Nathan Rixham skrev: before going any further, your HTML page is in UTF-8 yes? with the appropriate content-type line. Yes, apache uses only utf-8 as charset and the html content-type meta tag is set to utf-8 too. Also, the html form validates at validator.w3.org 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 I see the characters correctly, and page info in firefox says the encoding is utf-8. From the man page: "If a character is used in the string which is not supported by the font, a hollow rectangle will replace the character."... If you are 100% sure that the var $title contains a valid UTF-8 encoded text sting (simply output the string to the browser and set the page encoding to UTF-8), then the only thing that is left that might screw up the text-to-image output is the font you are using. As you might know, you can only use TrueType fonts. I am quite sure that the font supports the characters. I tried a couple of fonts that I use in other programs with utf-8. I am, however, not 100% sure that $title is correct utf-8, but I think it is. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: imagettftext and utf-8 (swedish characters)
On Fri, Feb 29, 2008 at 1:31 PM, Jochem Maas <[EMAIL PROTECTED]> wrote: > (my guess would be you could rely on all systems that have said TTF file > to support the same chars - I assume that although it may be compiled > diffferently > for different platforms the source font definition is going to be the same) I'm just blindly assuming (yes, ASS-uming) that the TTFs must be the same regardless, considering the portability across platforms. -- Daniel P. Brown Senior Unix Geek -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: imagettftext and utf-8 (swedish characters)
Daniel Brown schreef: On Fri, Feb 29, 2008 at 12:59 PM, Jochem Maas <[EMAIL PROTECTED]> wrote: it does because he's passing the title as an argument to the image script: I would say that's what I get for skimming, but look here: I guess I skimmed somewhat too ... but I based my assumption on the following from the OPs post: /index.php/slides/upload: $title = htmlentities($_POST['title'], ENT_COMPAT, 'UTF-8'); $image = '/index.php/slides/preview?title='.urlencode($title).'&content='.urlencode($_POST['content']); so the script handle the form submission looks to be generating a url used as the src of an img. ... Thus, it leads me back to my previous guess that the font he chose (georgia.ttf) doesn't have Swedish characters in the set. With that, I'm not sure, though, because I don't have the Georgia font pack on here, so it'll have to stay as a guess for now. Georgia.tff should cover swedish characters - atleast it does on my system (MPB) ... my little test script in my other post on this thread works for me ... I have no idea if one should/could expect variations of supported characters in a TTF font file depending on the system your on (my guess would be you could rely on all systems that have said TTF file to support the same chars - I assume that although it may be compiled diffferently for different platforms the source font definition is going to be the same) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: imagettftext and utf-8 (swedish characters)
On Fri, Feb 29, 2008 at 12:59 PM, Jochem Maas <[EMAIL PROTECTED]> wrote: > it does because he's passing the title as an argument to the image script: I would say that's what I get for skimming, but look here: > The form accepts (expects) UTF-8 (though the OP may be better with `latin1_swedish_ci`). Page encoding would only come into play here if the data was written as an HTML string. Form elements generally don't give a damn how the rest of the page is configured, because their job is only to be a container to pass POST and GET data to the server (which, again, couldn't care less what the previous page's encoding was prior to receiving the new data). The only places it will matter in this case, and in order, are: 1.) The FORM element (properly configured) 2.) The browser's capability to send data encoded in the desired encoding (likely true with the OP) 3.) The server's ability to handle the encoding (again, properly configured, according to David) Thus, it leads me back to my previous guess that the font he chose (georgia.ttf) doesn't have Swedish characters in the set. With that, I'm not sure, though, because I don't have the Georgia font pack on here, so it'll have to stay as a guess for now. -- Daniel P. Brown Senior Unix Geek -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: imagettftext and utf-8 (swedish characters)
Daniel Brown schreef: On Thu, Feb 28, 2008 at 9:17 PM, Nathan Rixham <[EMAIL PROTECTED]> wrote: before going any further, your HTML page is in UTF-8 yes? with the appropriate content-type line. That wouldn't matter, Nate. It's an image (and already rendered as a static graphical object). Page encoding won't make a difference here. it does because he's passing the title as an argument to the image script: okay, so foodledoodle is not proper swedish, but if you say it in a high voice it sounds a bit like it :-P -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: imagettftext and utf-8 (swedish characters)
On Thu, Feb 28, 2008 at 9:17 PM, Nathan Rixham <[EMAIL PROTECTED]> wrote: > before going any further, your HTML page is in UTF-8 yes? with the > appropriate content-type line. That wouldn't matter, Nate. It's an image (and already rendered as a static graphical object). Page encoding won't make a difference here. -- Daniel P. Brown Senior Unix Geek -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: imagettftext and utf-8 (swedish characters)
29 feb 2008 kl. 03.41 skrev David Sveningsson: Nathan Rixham skrev: before going any further, your HTML page is in UTF-8 yes? with the appropriate content-type line. Yes, apache uses only utf-8 as charset and the html content-type meta tag is set to utf-8 too. Also, the html form validates at validator.w3.org 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 I see the characters correctly, and page info in firefox says the encoding is utf-8. From the man page: "If a character is used in the string which is not supported by the font, a hollow rectangle will replace the character."... If you are 100% sure that the var $title contains a valid UTF-8 encoded text sting (simply output the string to the browser and set the page encoding to UTF-8), then the only thing that is left that might screw up the text-to-image output is the font you are using. As you might know, you can only use TrueType fonts. //frank ps sorry for posting my reply off-list the first time... ds. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: imagettftext and utf-8 (swedish characters)
Nathan Rixham skrev: before going any further, your HTML page is in UTF-8 yes? with the appropriate content-type line. Yes, apache uses only utf-8 as charset and the html content-type meta tag is set to utf-8 too. Also, the html form validates at validator.w3.org 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 I see the characters correctly, and page info in firefox says the encoding is utf-8. -- //*David Sveningsson [eXt]* Freelance coder | Game Development Student http://sidvind.com Thou shalt make thy program's purpose and structure clear to thy fellow man by using the One True Brace Style, even if thou likest it not, for thy creativity is better used in solving problems than in creating beautiful new impediments to understanding. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: imagettftext and utf-8 (swedish characters)
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) accept-charset="utf-8"> /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
Re: [PHP] Re: imagettftext and utf-8 (swedish characters)
Nathan Rixham skrev: 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)); It draws lesser squares, but no characters (except for the regular alphanum characters which is rendered correctly, as before). -- //*David Sveningsson [eXt]* Freelance coder | Game Development Student http://sidvind.com Thou shalt make thy program's purpose and structure clear to thy fellow man by using the One True Brace Style, even if thou likest it not, for thy creativity is better used in solving problems than in creating beautiful new impediments to understanding. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: imagettftext and utf-8 (swedish characters)
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) accept-charset="utf-8"> /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)); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php