Taking tutorial submissions! Please email them to dave[AT]icemelon[DOT]com for review. Thanks!

Latest Tutorials
IceMelon IM: Add IM Functionality to phpBB [Misc] Want to add site-wide member IM to your phpBB community? Sure you do. Simple step-by-step instructions inside.

IceMelon IM: Add IM Functionality to vBulletin [Misc] Want to add site-wide member IM to your vBulletin community? Simple step-by-step instructions inside.

Crawl Your Site for PageRanks [PHP] So you know your site has a PageRank of 8. What about the PRs of all the inner pages? This tutorial will teach how you to automate the process of grabbing all these PRs.

Create CAPTCHA images [PHP] Worried about bots? Then create CAPTCHA images to prevent bots from taking advantage of your site.

Convert SHN and FLAC files to MP3 [Misc] Low on disk space and have an insensitive ear? Here are some steps to converting SHN and FLAC files to MP3 format.

[View All]

Become a sponsor for $15/month. Link is sitewide - PR5 homepage, 20+ PR4 pages, 90+ PR3 pages. Email dave[AT]icemelon[D0T]c0m.

Awesome Tutorials

Dynamic Images
By dave

If you frequent forums, you'd probably remember images in people's signatures that would display information about your computer. Such mysticism! This tutorial will teach you that, and more!

First off, you need to have the GD module installed. To check, use the following PHP code:
echo "<xmp> ";
print_r( gd_info() );
echo "</xmp> ";
Here's what my output looks like:
Array
(
    [GD Version] => bundled (2.0.15 compatible)
    [FreeType Support] => 1
    [FreeType Linkage] => with freetype
    [T1Lib Support] =>
    [GIF Read Support] => 1
    [GIF Create Support] =>
    [JPG Support] => 1
    [PNG Support] => 1
    [WBMP Support] => 1
    [XBM Support] => 1
    [JIS-mapped Japanese Font Support] =>
)
If it's not installed on your server, you can grab it here [http://www.boutell.com/gd/].

The first step—perhaps the most difficult—is to create a PNG image that you want to insert text onto. Here's mine:


Now, I'm gonna get ahead of myself and show you the final product:


Pretty cool, huh? Now, here's the code:

Header ("Content-type: image/png");
$img_handle = imageCreateFromPNG("http://www.icemelon.com/images/tutorials/bannerboy.png");
$color = ImageColorAllocate ($img_handle, 100, 100, 100);
$ip = $_SERVER['REMOTE_ADDR'];
ImageString ($img_handle, 3, 10, 9,  "Your IP: $ip", $color);
ImagePng ($img_handle);
ImageDestroy ($img_handle);

Surprisingly, the code is quite short. It's also extremely straightforward.

Break it down
» First, we send the header information to let your visitor's computer know we're sending a PNG file.
» Next, the imageCreateFromPNG function creates your PNG image from the existing one I showed you first.
» Then we define a color (conveniently called $color) using ImageColorAllocate. The last three parameters specificy the RGB (red green blue) values, respectively. Enter those as integers (or as hex values, proceeded by 0x—e.g. 0xFA).
» Since we are displaying IP addresses, $ip is set to the visitor's IP.
» Finally, we are ready to add the text to the image, using ImageString. The three numerical parameters are defined as follows: font size, x-offset, and y-offset (respectively). For the font size, values 1 through 5 are predefined font sizes (1 being the smallest).
» The last two functions, ImagePng and ImageDestroy, are self explanatory.

Save the script above as whatever.php and you can now reference it in HTML as an image:
<img src="whatever.php">

Since it is a PHP script, you can modify the script slightly to grab values passed in through the filename. Here are a few examples of that concept in action:

   

——-
Try it out yourself:



For a plethora of related PHP functions, check out PHP.net's gd page. Have fun with it!

P.S. Check out my new site TheManWhoSoldtheWeb.com, where I publish guides and scripts on Internet Marketing and SEO. Here is a limited time freebie: the Rapid Google Indexer.


» Bookmark this Tutorial
» Bookmark IceMelon
Icemelon -- Dynamic Images -- PHP, CSS, Javascript Tutorials, & More!
  © 2005-2010 Icemelon.com   Email: dave[AT]icemelon[D0T]c0m