"Ziying Sherwin" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > > In our application, we need to write a UTF8 strings to the image using True > Type fonts. The php function that we are using is imagettftext. However, > we have the two problems regarding that function: > > 1. The images that are generated by this function is white fonts on the black > background. But what we want is black fonts on the white background. It > seems impossible to set the background color. What we are doing now is to > call external commands to reverse the color which is rather slow. Is there > better way to achieve the same result?
How about this example: var $width = 200; var $height = 50; var $offset_x = 0; var $offset_y = 10; var $font = '/usr/share/fonts/times.ttf'; //default font. var $msg = "Hello!"; var $size = 24; var $rot = 0; // rotation in degrees. var $transparent = 1; // transparency set to on. var $red = 0; // black text... var $grn = 0; var $blu = 0; var $bg_red = 255; // on white background. var $bg_grn = 255; var $bg_blu = 255; var $truecolor = false; if($truecolor) { $image = ImageCreateTrueColor($width,$height); $background = ImageColorResolveAlpha($image, $bg_red, $bg_grn, $bg_blu, $transparent?127:0); $foreground = ImageColorAllocate($image, $red, $grn, $blu); ImageFilledRectangle($image, 0, 0, $width, $height, $background); } else { $image = ImageCreate($width, $height); $background = ImageColorAllocate($image, $bg_red, $bg_grn, $bg_blu); if($transparent) ImageColorTransparent($image, $background); ImageFilledRectangle($image, 0, 0, $width, $height, $background); $foreground = ImageColorAllocate($image, $red, $grn, $blu); } ImageTTFText($image, $size, $rot, $offset_x, $offset_y, $foreground, $font, $msg); Header("Content-type: image/png"); ImagePNG($image); > 2. We also have long UTF8 stings that need to be broken into several lines. > Which php function has the ability to properly break UTF8 strings? And > how to display multiple lines using imagettftext? I guess you have to develop an algorithm do line breaks your self ImageTTFBBox() should provide you with data to make it possible. -- Stellan Klebom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php