<?php
/*
May 10, 2000.
Written and tested on PHP 4.0 RC1 (mod_php)
Linux/Apache. Tried on PHP 3.0.14 Win2000/IIS
5.0 for a minute or two, it worked.
==============================================================
This script is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Copyright (c)2000 Pierre Marceau. You may freely use
and redistribute under the terms of the GNU General Public
License.
--------------------------------------------------------------
gif2function - http://www.skynet.ca/~pierre/
==============================================================
This script converts gif files into PHP functions.
See example.php3. Use small gif files 2 or 3 kb
max. I use it for one 800 byte (0.8KB) background image
file.
*/
## Change this to the gif file that you would like to convert.
## You don't need to change anything else.
$filename = "php4.gif";
if (!is_file($filename)) {echo "File not found: <b>$filename</b>"; return;}
$new_func = "\n\n";
$new_name = ereg_replace(".gif","gif",$filename);
$fsize = filesize($filename);
$fd = fopen($filename,"r");
$contents = fread($fd,$fsize);
fclose($fd);
$b64 = base64_encode($contents);
// OK lets output the new function to
// the browser so you can cut'n'paste
// it into your script.
$new_func .= " function $new_name() {\n";
$new_func .= " header(\"Content-type: image/gif\");\n";
$new_func .= " header(\"Content-length: ${fsize}\");\n";
$new_func .= " echo base64_decode(\n '";
$new_func .= chunk_split($b64,35,"'.\n '");
//Cleanup the last "'.\n '" from chunk_split
$new_func = ereg_replace("'.\n '$","');\n }",$new_func);
$new_func .= "\n\n";
if ($action=="go") {
//must have been called from the body tag
//parse this new function
eval($new_func);
//execute the function
$new_name();
return;
}
?>
<html>
<head>
</head>
<body background="<?php echo "$PHP_SELF"; ?>?action=go">
<div align="center">
<table border="15" bgcolor="white">
<tr bgcolor="white">
<th bgcolor="white">
<font size="+1">
You may now simply cut and paste<br>this function into your script.
</font>
</th>
</tr>
<tr>
<td>
<form>
<textarea cols="45" rows="18"><?php echo $new_func ?></textarea>
</form>
</td>
</tr>
<tr>
<td align="center">
<a href="http://www.skynet.ca/~pierre/" target="_blank">EditPHP, check it out!</a>
</td>
</tr>
</table>
</div>
</body>
</html>
|