R
E
S
O
U
R
C
E
S
       Home      Products & Services      Contact Us      Links


WebHatchers will design & develop your site for you.
_______________________

Website Menu Heaven: menus, buttons, etc.
_______________________

Send us your questions.
_______________________

site search by freefind
_______________________

HOME
SEO, Google, Privacy
   and Anonymity
Browser Insanity
JavaScript
Popups and Tooltips
Free Website Search
HTML Form Creator
Animation
Buttons and Menus
Counters
Captchas
Image Uploading
CSS and HTML
PHP
AJAX
XPATH
Website Poll
IM and Texting
Databases—MySQL
   or Not MySQL
Personal Status Boards
Content Management
   Systems
Article Content
   Management Systems
Website Directory
   CMS Systems
Photo Gallery CMS
Forum CMS
Blog CMS
Customer Records
   Management CMS
Address Book CMS
Private Messaging CMS
Chat Room CMS
JavaScript Charts
   and Graphs




Personal Status Boards (PSB™)

Standard Free PSB

PSB Pro Version

Social PSB

Social PSB Plus (with Email)

Business PSB

Business PSB Plus (with Email)

PSB demo

Social PSB demo

Business PSB demo

So what's all this PSB stuff about?

Chart comparing business status boards

PSB hosting diagram

PSB Licence Agreement



Copyright © 2002 -
MCS Investments, Inc. sitemap

PSBs, social networking, social evolution, microcommunities, personal status boards
PSBs, social networking, business personal status boards
website design, ecommerce solutions
website menus, buttons, image rotators
Ez-Architect, home design software
the magic carpet and the cement wall, children's adventure book
the squirrel valley railroad, model railroad videos, model train dvds
the deep rock railroad, model railroad videos, model train dvds

PHP Script for Writing PNG Image Files

PHP can write just about anything. The script below will concentrate on PNG Image files.

Permissions

The one thing you need to watch here is permissions. On some servers, you need permissions (CHMOD) set to 755 to use the PHP fwrite function, which all the file creations below use in their code. But on other servers (like ours, we discovered), you need permissions set to 777. There are people that understand why. We are not those people, nor is our server host. Older servers seem to need 777. Newer servers need only 755—which is obviously more secure. But this is not a hard and fast rule—your mileage may vary. If you find that you need 777, you may find your host blocks this setting. But you may find you can fwrite with only a 755 CHMOD (public_html AND the PHP script file setting). Some hosts disallow fwrite and even PHP file functions in general. You will find that write-nearly-any-type-of-file-with-php.html is the best place you can go for answers if you are testing a PHP script for writing a file and you get the dreaded permission error message.

Writing Various Types of Files

There are times when you just need to use PHP to write various types of files. The list below shows you how—it's not hard at all. There are even five PHP scripts for creating graphics/image files. For image creation, we concentrated on the simple task of allowing users to input text and using PHP to take this text and put it in a nice box with a border and save it as a graphics/image file. Let us know how you like these scripts! We kept them as simple as we could so you could get the idea in a flash.



The PHP Script for Writing PNG Image Files

First, notice that we are counting on the GD library to have been enabled in your PHP installation. It usually is, but if it is not, get your host to do so. The
imagepng() function from the GD library is needed—along with several other functions—for this image creation to work. What the 2 scripts below do is turn your typed text input and turn it into an actual PNG image (as long as you have the correct permissions to do this—ask your host).

The mytext-convert-to-png-image.php script is mostly an HTML input form and the form action is to run this same file, mytext-convert-to-png-image.php. When it does this page refresh, it POSTs the text to an image-png.php image creation file. Note that the text gets sent via URL query string in the variable "mytext".

Once the text gets to the image-png.php script, the script GETs it into the PHP variable $mytext. Variables are defined using the imagefontwidth() and imagefontheight() functions from the GD library. The adding of 20 is to give the final image padding so the words are not jammed against the image edge. Next we use imagecreatetruecolor() to create a new true color image of the needed size. Next we use imagecolorallocate() to allocate colors for the image. The numbers in the argument are RGB color numbers. Then we use the imagefill() function to fill the image with one of the colors. The imageline() function is used to draw a border around the image. The argument numbers are X1 Y1 X2 Y2, which is saying to draw a line from X1,Y1 to X2,Y2. The minus ones in some of the arguments keep the function from trying to draw outside of the edge of the image. The imagestring() function types our text into the image. The numbers are x-coordinate of the upper left corner of the text string and y-coordinate of the upper left corner of the text string. Given that we made the image 20 wider and taller than the text, using 10 now as the offset centers the text in the image. The imagepng() function creates this finished image onscreen, and when used with a file name, it creates the PNG image on the server. The imagedestroy() function frees any memory associated with image creation. This is advisable.

If you want to learn PHP because you do not know it, check out a PHP tutorial.

Here is the result:

Here is the file mytext-convert-to-png-image.php where you input text to be written as a PNG image:

<html>
<head>
</head>
<body>

<?php

$mytext=$_POST['mytext'];
if(isset($mytext)){print '<img src="image-png.php?mytext=' . $mytext . '">';}

?>

<table width="654" border="1" align="center" cellpadding="3" cellspacing="0" bgcolor="#ffffff">
<tr>
<td align='center'><b><h2>Enter Some Text</h2></b></td>
</tr>
</table>
<table width="650" border="1" align="center" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
<tr>
<form name="form" method="post" action="mytext-convert-to-png-image.php">
<td>
<table width="650" border="0" cellpadding="3" cellspacing="1" bgcolor="#ffffff">
<tr>
<td><b>Enter text to convert to image</b></td>
</tr>
<tr>
<td><input name="mytext" type="text" size="100" maxlength="100"></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit" value="Reset"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</body>
</html>

Here is the image-png.php file called by the above file:

<?php

header("Content-type: image/png");
$mytext = $_GET['mytext'];
$fontsize = 5;
$wide = imagefontwidth($fontsize) * strlen($mytext) + 20;
$high = imagefontheight($fontsize) + 20;
$picture = imagecreatetruecolor($wide,$high);
$gray = imagecolorallocate($picture,223,223,223);
$blue = imagecolorallocate($picture,0,0,255);
imagefill($picture,0,0,$gray);
$black=imagecolorallocate($picture, 0, 0, 0);
imageline($picture, 0, 0, 0, $high, $black);
imageline($picture, 0, 0, $wide, 0, $black);
imageline($picture, $wide-1, 0, $wide-1, $high-1, $black);
imageline($picture, 0, $high-1, $wide-1, $high-1, $black);
imagestring($picture,$fontsize,10,10,$mytext,$blue);
imagepng($picture);
imagepng($picture,"mytextpic.png");
imagedestroy($picture);

?>