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
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)
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 åäö (#0197; 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] 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
[PHP] imagettftext and utf-8 (swedish characters)
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(); } -- //*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)
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
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] Start/stop daemon using php
Hi, I've written an application in c which I would like to start/stop as a daemon in gnu/linux. The application has the argument --daemon which forks the process and exits the parent. Then it setups a SIGQUIT signal handler to properly cleanup and terminate. It also maintains a lockfile (with the pid) so only one instance is allowed. So, to start this application I created a php site that calls exec(/path/to/binary --daemon /dev/null 2 /dev/null). Everything is working so far, but I cannot get the application to receive the SIGQUIT when I start using php and exec. Not even manually using kill in the shell. It works correctly if I start manually thought. So, is this possible to do? Doesn't exec allow applications with signal handlers? Is there some other way to terminate the application? -- //*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] Start/stop daemon using php
@4u skrev: Hi, You might consider D-BUS for your application and the D-BUS PHP binding which is available since some days too. This would allow you to start / stop your C application in a far more secure way than the suggested one. Please have a look at my original release annoucement at the D-BUS mailing list: http://lists.freedesktop.org/archives/dbus/2008-February/009363.html as well as the download URL: https://sourceforge.net/project/showfiles.php?group_id=17176package_id=68954 D-BUS sounds excellent, I will definitely try it out. I have never coded D-BUS myself but I don't think it would be too hard. Even if the application runs on Windows you might be able to use D-BUS for communication. Currently neither the application or the frontend is planned to support windows as it is already full of very unix specific code. -- //*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] Start/stop daemon using php
Per Jessen skrev: David Sveningsson wrote: Hi, I've written an application in c which I would like to start/stop as a daemon in gnu/linux. The application has the argument --daemon which forks the process and exits the parent. Then it setups a SIGQUIT signal handler to properly cleanup and terminate. It also maintains a lockfile (with the pid) so only one instance is allowed. So, to start this application I created a php site that calls exec(/path/to/binary --daemon /dev/null 2 /dev/null). Everything is working so far, but I cannot get the application to receive the SIGQUIT when I start using php and exec. Not even manually using kill in the shell. It works correctly if I start manually thought. So obviously something is catching the SIGQUIT before it gets to your daemon. You mention a php site, so I take it you're running apache. In an apache process you then do an exec(something). I think apache is probably taking care of the SIGQUIT. Yes, I am using apache (forgot to mention it). Is there a way to stop apache from catching the signals? So, is this possible to do? Doesn't exec allow applications with signal handlers? Is there some other way to terminate the application? Why do you have to kill it with an explicit signal - why not not have a way of communicating with the process that'll make it terminate when you raise a flag or send it a message or something. Currently I have no other way of communicating than a mysql database (it passes data that needs processing) so I thought it would be quick and easy to just raise a signal. I read in another mail about D-BUS which I think would be a better way of communication. /Per Jessen, Zürich -- //*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