PHP GD help |
Author: |
Message: |
Ezra
Veteran Member
Forgiveness is between them and God
Posts: 1960 Reputation: 31
37 / /
Joined: Mar 2003
|
O.P. PHP GD help
I made a small code to make a random text-sig some while ago, and today I added Sign the Petition to it, but I realised it was too small to fit the text, so I made it double the size, but not it doesn't look nice with smaller texts anymore...
Anywaaaay, what im trying to ask is , can someone help me to make it auto-adjust the size to the text.
I already tried it with imagettfbox but couldn't get it to work. Because I don't think my server can use ttf font's, and I can't change any settings cause it's my hosting company's server.
TIA
And below my code
code: <?php
//randomizer
srand((float) microtime() * 10000000);
$input = array("Ezra", "TSDME", "MsgPlus!", "Nintendo", "SPAM", "Web2Messenger", "Sign the Petition");
$rand_keys = array_rand($input, 2);
$string = $input[$rand_keys[0]];
//Header info
header("Content-type: image/gif");
//
$im = @imagecreate(160, 20);
$background_color = imagecolorallocate($im, 100, 100, 100);
$text_color = imagecolorallocate($im, 000, 000, 200);
//
imagecolortransparent($im, $background_color);
imagestring($im, 5, 7, 3, $string, $text_color);
imagegif($im);
imagedestroy($im);
//statistics
include_once('connection.inc.php');
opendb();
$query = "SELECT * FROM stats";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
$sts = ($row[stats]) + 1;
}
$sql = "UPDATE stats
SET stats = '$sts'";
mysql_query($sql);
?>
|
|
09-08-2005 07:35 PM |
|
|
KeyStorm
Elite Member
Inn-sewer-ants-pollie-sea
Posts: 2156 Reputation: 45
38 / / –
Joined: Jan 2003
|
RE: PHP GD help
imagettfbox is very picky with the font path. Firstly you should check your PHPinfo to see if freetext (2 if possible) is installed.
This post was edited on 09-08-2005 at 07:57 PM by KeyStorm.
|
|
09-08-2005 07:57 PM |
|
|
Ezra
Veteran Member
Forgiveness is between them and God
Posts: 1960 Reputation: 31
37 / /
Joined: Mar 2003
|
O.P. RE: PHP GD help
Freetext is not installed, Gettext is installed not sure if that's any use to it, but it's called text so I thougt it might be worth telling
And I have PHP4 and 5 btw, so I can also use PHP5only functions if needed.
|
|
09-08-2005 08:03 PM |
|
|
KeyStorm
Elite Member
Inn-sewer-ants-pollie-sea
Posts: 2156 Reputation: 45
38 / / –
Joined: Jan 2003
|
RE: PHP GD help
Well... check if the GD section of any of both versions says something about fonts or ttf?
Do you get an error when you use that function and not change the headers to image?
|
|
09-08-2005 08:16 PM |
|
|
Ezra
Veteran Member
Forgiveness is between them and God
Posts: 1960 Reputation: 31
37 / /
Joined: Mar 2003
|
O.P. RE: PHP GD help
Stupid Windows FTP, I needed to upload the .ttf file in binary mode, but somehow Windows transferred in ASCII mode or something, because when I forced Binary mode with FireFTP It worked
Anywaay, still working on it, the text looks a bit strange, I'll see if I can make it better and to get the resizing to work
progress: http://scripts.tsdme.nl/randomgif.php
|
|
09-08-2005 11:02 PM |
|
|
brian
Senior Member
Posts: 819 Reputation: 43
– / / –
Joined: Sep 2004
|
RE: PHP GD help
I don't like the font? Or is it my explorer?
|
|
09-08-2005 11:09 PM |
|
|
Ezra
Veteran Member
Forgiveness is between them and God
Posts: 1960 Reputation: 31
37 / /
Joined: Mar 2003
|
O.P. RE: PHP GD help
I don't like it either it's supposed to be arial, but it's buttugly right now
Anywaay, the resizing works
Now, I just need to make the font look nice
UH.... It's not showing on IE , it's just a GIF with transparancy...
Hmm, nvm, working now on IE , crazy IE...
So does anyone know how to make it look nicer?
BTW: I still want a transparent background.
This post was edited on 09-09-2005 at 12:13 AM by Ezra.
|
|
09-08-2005 11:24 PM |
|
|
KeyStorm
Elite Member
Inn-sewer-ants-pollie-sea
Posts: 2156 Reputation: 45
38 / / –
Joined: Jan 2003
|
RE: PHP GD help
Gif will always do hard backgrounds.
Youy may use PNG.
[code]
$img = imagecreatetruecolor($width, $height)
imageAlphaBlending($img, true);
imageSaveAlpha($img, true);
imagecolorallocate($img,0,0,0,127);
[/color]
This will make a transparent backgrounded PNG
You must note that MSIE 6 is the only browser that does not support them. 7 is said to do.
|
|
09-09-2005 01:35 PM |
|
|
Ezra
Veteran Member
Forgiveness is between them and God
Posts: 1960 Reputation: 31
37 / /
Joined: Mar 2003
|
O.P. RE: PHP GD help
On the php.net pages it says I can't use imagesavealpha when imagealphablending is enabled
And I keep having a black background for some reason
|
|
09-09-2005 02:37 PM |
|
|
L. Coyote
Senior Member
Captain Obvious
Posts: 981 Reputation: 49
39 / /
Joined: Aug 2004
Status: Away
|
RE: PHP GD help
quote: Originally posted by Ezra
And I keep having a black background for some reason
Are you using IE?
quote: Originally posted by KeyStorm
You must note that MSIE 6 is the only browser that does not support them. 7 is said to do.
Hack, hack, hack!
Finally became a Systems Analyst!
|
|
09-09-2005 02:40 PM |
|
|
Pages: (2):
« First
[ 1 ]
2
»
Last »
|
|