Rotator 0 Report post Posted November 19, 2006 Hey Having browsed this and other sites I've come up with the following signature-code for generating text on an image: <?php header("Content-type: image/png"); $select = rand(1,3);if($select==1)$img = "gow.png";if($select==2)$img = "gow2.png";if($select==3)$img = "gow3.png";$image = imagecreatefrompng("$img");//imagecolorallocate($image, R, G, B) in HEX values$font_white = imagecolorallocate($image, 255, 255, 255);$font_grey = imagecolorallocate($image, 128, 128, 128);$select = rand(1,3);if($select==1)$string1 = "Achievement Status";if($select==1)$string2 = "4395 Gamerpoints";if($select==2)$string1 = "Latest Game";if($select==2)$string2 = "Gears of War";if($select==3)$string1 = "Latest Achievement";if($select==3)$string2 = "Veteran of D-Day (Call of Duty 2)";//($image, fontsize, rightindent, downindent, data, txtcolour)imagestring($image, 3, 7, 5, "Collection Status", $font_white);imagestring($image, 3, 7, 23, "48 Retail Xbox360 Titles", $font_white);imagestring($image, 3, 7, 41, $string1, $font_white); imagestring($image, 3, 7, 59, $string2, $font_white); imagepng($image); imagedestroy($image); ?> However, it generates the text in the image in a standard font. Is there a way to make it use a different truetype font, one located on the same server as the php, but not installed on the hostmachine?I'm REALLY new to php, so please reply in plain english Thanks in advance. Share this post Link to post Share on other sites
rvalkass 5 Report post Posted November 19, 2006 I know it is possible to use a non-standard font on a signature as I did it a while ago. You have to upload the TTF font file to the same directory as the script for it to work. I haven't used it for a while, but I got the code from the PHP manual. Have a look over there and I'll root around and see if I can find the code I used. Share this post Link to post Share on other sites
Rotator 0 Report post Posted November 19, 2006 I tried replacing imagestring with imagettftext and adding $font = 'lcd.ttf';. The lcd.ttf is uploaded to the same dir. I see the image as it's supposed to look, but no text... Share this post Link to post Share on other sites
truefusion 3 Report post Posted November 19, 2006 Ah, my method is a bit different (see my sig block). I filled an array full of phrases, and used array_rand to randomly pick which one to display per load. I even made it to match the background of the forum. Just the profile background is a bit different. I chose the font Arial just so it can look plain. Other fonts would have worked, though.Btw, in the code you have shown, you don't specify which font to use, like i did in my code. Share this post Link to post Share on other sites
Rotator 0 Report post Posted November 19, 2006 Now, how can I get to see your code? If you'll let me? :blink:The first code I wrote didn't have any information about the font, because I didn't know what to do...But as I said, I tried imagettftext in conjunction with $font, but to no avail... Share this post Link to post Share on other sites
truefusion 3 Report post Posted November 19, 2006 Here is the coding for mine: <?phpheader("Content-type: image/png");$arr = array("random text","random text","random text","random text","random text","random text","random text");$string = $arr[array_rand($arr)];$i = 10;$font = "../fonts/arial.ttf";$size = imagettfbbox($i, 0, $font, $string);$width = ($size[2]+3) + ($size[0]+3);$height = abs($size[1]+3) + abs($size[7]+3);$im = @imagecreate($width, $height) or die("Cannot Initialize new GD image stream");$bgcolor = imagecolorallocate($im, 238, 242, 247);$text_color = imagecolorallocate($im, 0, 0, 0);imagettftext($im, $i, 0, 2, abs($size[5]), $text_color, $font, $string); imagepng($im);imagedestroy($im);?>It is also made to adjust the width and height to fit the text. Share this post Link to post Share on other sites
Rotator 0 Report post Posted November 20, 2006 Thanks alot, guys! I finally got the look I was searching for. Had to tweak the code alot, but it works now... <?phpheader("Content-type: image/png");$select = rand(1,3);if($select==1)$string1 = "Achievement Status";if($select==1)$string2 = "4395 Gamerpoints";if($select==2)$string1 = "Latest Game";if($select==2)$string2 = "Gears of War";if($select==3)$string1 = "Latest Achievement";if($select==3)$string2 = "Veteran of D Day";if($string1=="Achievement Status")$I1 = "65";if($string2=="4395 Gamerpoints")$I2 = "74";if($string1=="Latest Game")$I1 = "97";if($string2=="Gears of War")$I2 = "87";if($string1=="Latest Achievement")$I1 = "66";if($string2=="Veteran of D Day")$I2 = "72";$i = 14;$font = "lcd.ttf";$size = imagettfbbox($i, 0, $font, $string);$im = @imagecreate(300, 80) or die("Cannot Initialize new GD image stream");$bgcolor = imagecolorallocate($im, 0, 64, 0);$text_color = imagecolorallocate($im, 0, 255, 0);$text_color2 = imagecolorallocate($im, 0, 128, 0);imagettftext($im, $i, 0, 5, 20, $text_color2, $font, "88888888888888888888888888888"); imagettftext($im, $i, 0, 70, 20, $text_color, $font, "COLLECTION STATUS"); imagettftext($im, $i, 0, 5, 38, $text_color2, $font, "88888888888888888888888888888"); imagettftext($im, $i, 0, 39, 38, $text_color, $font, "48 RETAIL XBOX360 TITLES");imagettftext($im, $i, 0, 5, 56, $text_color2, $font, "88888888888888888888888888888"); imagettftext($im, $i, 0, $I1, 56, $text_color, $font, $string1); imagettftext($im, $i, 0, 5, 74, $text_color2, $font, "88888888888888888888888888888"); imagettftext($im, $i, 0, $I2, 74, $text_color, $font, $string2);imagepng($im);imagedestroy($im);?> Giving me that following image with the first two lines static and the other two random Share this post Link to post Share on other sites
farsiscript 0 Report post Posted November 20, 2006 Hi Dear Rotator i agree Rotator post , but dear Rotator i have one question about fonts and css . how we can use tff fonts in css files with out visitors download that fonts ? Share this post Link to post Share on other sites
Rotator 0 Report post Posted November 20, 2006 Hi Dear Rotator i agree Rotator post , but dear Rotator i have one question about fonts and css . how we can use tff fonts in css files with out visitors download that fonts ? Well, I never worked with Cascading Style Sheets (CSS) before, so that would be a question for someone else Sorry. Share this post Link to post Share on other sites
Rotator 0 Report post Posted November 20, 2006 Okay, new question:With the current code, I have to manually changed the left indent of the text whenever I edit it, to make sure it's centered on the image...Isn't there a way to automatically ensure that the text is centered? Share this post Link to post Share on other sites
Imtay22 0 Report post Posted April 9, 2007 A simalar code has been posted about the same thing. Almost exactly the same.@ Rotator-Check out this link- {link}. It has centered and left text in it. Share this post Link to post Share on other sites