|
|
|
|
![]() ![]() |
Nov 19 2006, 02:08 PM
Post
#1
|
|
|
Newbie ![]() Group: Members Posts: 6 Joined: 19-November 06 Member No.: 33,667 |
Hey
Having browsed this and other sites I've come up with the following signature-code for generating text on an image: CODE <?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. |
|
|
|
Nov 19 2006, 03:09 PM
Post
#2
|
|
|
apt-get moo ![]() Group: [MODERATOR] Posts: 2,153 Joined: 28-May 05 From: Devon, England Member No.: 7,593 ![]() |
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.
|
|
|
|
Nov 19 2006, 05:47 PM
Post
#3
|
|
|
Newbie ![]() Group: Members Posts: 6 Joined: 19-November 06 Member No.: 33,667 |
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... |
|
|
|
Nov 19 2006, 06:38 PM
Post
#4
|
|
|
Ephesians 6:10-17 ![]() Group: [MODERATOR] Posts: 1,918 Joined: 22-June 05 From: The World of Gentoo Member No.: 8,528 |
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. |
|
|
|
Nov 19 2006, 06:57 PM
Post
#5
|
|
|
Newbie ![]() Group: Members Posts: 6 Joined: 19-November 06 Member No.: 33,667 |
Now, how can I get to see your code? If you'll let me?
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... |
|
|
|
Nov 19 2006, 07:17 PM
Post
#6
|
|
|
Ephesians 6:10-17 ![]() Group: [MODERATOR] Posts: 1,918 Joined: 22-June 05 From: The World of Gentoo Member No.: 8,528 |
Here is the coding for mine:
CODE <?php header("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. |
|
|
|
Nov 20 2006, 06:13 AM
Post
#7
|
|
|
Newbie ![]() Group: Members Posts: 6 Joined: 19-November 06 Member No.: 33,667 |
Thanks alot, guys!
I finally got the look I was searching for. Had to tweak the code alot, but it works now... CODE <?php header("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
|
|
|
|
Nov 20 2006, 07:24 AM
Post
#8
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 357 Joined: 8-April 06 Member No.: 21,487 |
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 ?
|
|
|
|
Nov 20 2006, 09:23 AM
Post
#9
|
|
|
Newbie ![]() Group: Members Posts: 6 Joined: 19-November 06 Member No.: 33,667 |
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. |