mck9235
03-05-2005, 11:37 PM
This tutorial shows you how to create a dynamic image using PHP. First lets show the actual file:
<?php
$dayToCountDownTo = 1;
$daysAway = $dayToCountDownTo - intval(date("z"));
$text = "Your text here " . strval($daysAway);
$fontSize = 7;
$ImageWidth = imagefontwidth($fontSize) * strlen($text);
$ImageHeight = imagefontheight($fontSize);
$Image = imagecreatefromjpeg("http://www.bg.com/background.jpeg");
$BgColor = imagecolorallocate($Image, 255, 255, 255);
imagecolortransparent($Image, $BgColor);
$TextColor = imagecolorallocate($Image, 0, 114, 173);
imagestring($Image, $fontSize, 0, 0, $text, $TextColor);
header("Content-type: image/png");
imagepng($Image);
imagedestroy($Image);
?>
There is only a couple things you need to edit, the first is the total days until your countdown, then your text, then the font size, then on this line:
$Image = imagecreatefromjpeg("http://www.bg.com/background.jpeg");
Change the URL to the URL of your desired background image.
Next we need the color of the font, this is done in RGB
$TextColor = imagecolorallocate($Image, 0, 114, 173);
Edit the three numbers, leaving the formatting the same!
Check this page out for many common RGB values: http://www.w3schools.com/html/html_colors.asp
Okay now you should be done editing the file, save it as image.php and upload it to your server.
Now lets look at the code to display the image:
<table width="360" height="250">
<tr>
<td valign="middle" style="background-image: url(‘http://www.placehwerebgimageis.com);"><img src="http://www.placewherephpfileis.com " />
</td>
</tr>
</table>
As you see you need to edit three things, in the top line the two values, change those to the width and height of your background image. The first URL is the URL of your background image and the second is the URL of the PHP file we made above. Once you edit those two just save it and upload it, then you can acess the image by:
http://www.whereuploaded.ext/phpfile.php?ext=.png
Having ext=.png enables you to use it in the tags on a forum.
Note: /phpfile,php?ext=.png is the first PHP file.
[i]Code from this tutorial was used with permission from Tim at http://www.tm-software.uni.cc
<?php
$dayToCountDownTo = 1;
$daysAway = $dayToCountDownTo - intval(date("z"));
$text = "Your text here " . strval($daysAway);
$fontSize = 7;
$ImageWidth = imagefontwidth($fontSize) * strlen($text);
$ImageHeight = imagefontheight($fontSize);
$Image = imagecreatefromjpeg("http://www.bg.com/background.jpeg");
$BgColor = imagecolorallocate($Image, 255, 255, 255);
imagecolortransparent($Image, $BgColor);
$TextColor = imagecolorallocate($Image, 0, 114, 173);
imagestring($Image, $fontSize, 0, 0, $text, $TextColor);
header("Content-type: image/png");
imagepng($Image);
imagedestroy($Image);
?>
There is only a couple things you need to edit, the first is the total days until your countdown, then your text, then the font size, then on this line:
$Image = imagecreatefromjpeg("http://www.bg.com/background.jpeg");
Change the URL to the URL of your desired background image.
Next we need the color of the font, this is done in RGB
$TextColor = imagecolorallocate($Image, 0, 114, 173);
Edit the three numbers, leaving the formatting the same!
Check this page out for many common RGB values: http://www.w3schools.com/html/html_colors.asp
Okay now you should be done editing the file, save it as image.php and upload it to your server.
Now lets look at the code to display the image:
<table width="360" height="250">
<tr>
<td valign="middle" style="background-image: url(‘http://www.placehwerebgimageis.com);"><img src="http://www.placewherephpfileis.com " />
</td>
</tr>
</table>
As you see you need to edit three things, in the top line the two values, change those to the width and height of your background image. The first URL is the URL of your background image and the second is the URL of the PHP file we made above. Once you edit those two just save it and upload it, then you can acess the image by:
http://www.whereuploaded.ext/phpfile.php?ext=.png
Having ext=.png enables you to use it in the tags on a forum.
Note: /phpfile,php?ext=.png is the first PHP file.
[i]Code from this tutorial was used with permission from Tim at http://www.tm-software.uni.cc