JaxPHP / JaxWeb Message Board › Total PHP Novice in need of assistance

Total PHP Novice in need of assistance

A former member
Post #: 1
I am trying to build a Cost savings thermometer I downloaded a free script but for some reason the values I am putting in the html form are not being pulled by the PHP.

PHP script:

<?php
/*
Fundraising Thermometer Generator v1.1
Sairam Suresh /

NOTE - you must include the full path to the truetype font on your system below
if you want text labels to appear on your graph. No TrueType fonts are
included in this package, you can probably find some on your system or
else download one off the net.


Inputs: 'unit' - the ascii value of the currency unit. By default 36 ($)
other interesting ones are:
163: British Pound
165: Japanese Yen
8355: French Franc
8364: Euro

'max' - the goal
'current' - the current amount raised

Versions:
1.2 - added a 'burst' image on request, cleaned up the images a little bit.
1.1 - Internationalized :) added 'unit' at a user's request so other currencies could be used.
1.0 - intial version

*/
error_reporting(7); // Only report errors
Header("Content-Type: image/jpeg");

function code2utf($num){
//Returns the utf string corresponding to the unicode value
//courtesy - romans@void.lv
if($num<128)return chr($num);
if($num<2048)return chr(($num>>6)+192).chr(($num&6­3)+128);
if($num<65536)return chr(($num>>12)+224).chr((($num>­>6)&63)+128).chr(($num&63)+12­8);
if($num<2097152)return chr(($num>>18)+240).chr((($num>­>12)&63)+128).chr((($num>>6­)&63)+128). chr(($num&63)+128);
return '';
}

#$font = "/usr/local/fonts/ttf/arial.ttf";­
$font = "c:/windows/fonts/georgia.ttf";­

$unit = ($_POST["unit"]) ? $_POST['unit'] : 36; // ascii 36 = $
$t_unit = ($unit == 'none') ? '' : code2utf($unit);
$t_max = ($_POST["max"]) ? $_POST["max"] : 0;
$t_current = isset($_POST["current"]) ? $_POST["current"] : 0;

$finalimagewidth = max(strlen($t_max),strlen($t_current))*25;­
$finalimage = imagecreateTrueColor(60+$finalimagewidth­,405);
$white = imagecolorallocate ($finalimage, 255, 255, 255);
$black = imagecolorallocate ($finalimage, 0, 0, 0);
$red = imagecolorallocate ($finalimage, 255, 0, 0);

imagefill($finalimage,0,0,$white);
ImageAlphaBlending($finalimage, true);

$thermImage = imagecreatefromjpeg("therm.jpg"­);
$tix = ImageSX($thermImage);
$tiy = ImageSY($thermImage);
ImageCopy($finalimage,$thermImage,0,0,­0,0,$tix,$tiy);
/*
thermbar pic courtesy http://www.rosiehardm...­
*/
$thermbarImage = ImageCreateFromjpeg('thermbar.jpg');
$barW = ImageSX($thermbarImage);
$barH = ImageSY($thermbarImage);
$xpos = 5;
$ypos = 327;
$ydelta = 15;
$fsize = 12;
// Set number of $ybars to use, calculated as a factor of current / max.
if ($t_current > $t_max) {
$ybars = 25;
} elseif ($t_current > 0) {
$ybars = $t_max ? round(20 * ($t_current / $t_max)) : 0;
}
// Draw each ybar (filled red bar) in successive shifts of $ydelta.
while ($ybars--) {
ImageCopy($finalimage, $thermbarImage, $xpos, $ypos, 0, 0, $barW, $barH);
$ypos = $ypos - $ydelta;
}
if ($t_current == $t_max) {
ImageCopy($finalimage, $thermbarImage, $xpos, $ypos, 0, 0, $barW, $barH);
$ypos -= $ydelta;
}
// If there's a truetype font available, use it
if ($font && (file_exists($font))) {
imagettftext ($finalimage, $fsize, 0, 60, 355, $black, $font,$t_unit."0"); // Write the Zero
imagettftext ($finalimage, $fsize, 0, 60, 10+(2*$fsize), $black, $font, $t_unit."$t_max"); // Write the max
if ($t_current > $t_max) {
imagettftext ($finalimage, $fsize+1, 0, 60, $fsize, $black, $font, $t_unit."$t_current!!"); // Current > Max
} elseif($t_current != 0) {
if ($t_current == $t_max) {
imagettftext ($finalimage, $fsize, 0, 60, 10+(2*$fsize), $red, $font, $t_unit."$t_max!"); // Current = Max
} else {
if (round($t_current/$t_max) == 1) {
$ypos += 2*$fsize;
}
imagettftext ($finalimage, $fsize, 0, 60, ($t_current > 0) ? ($ypos+$fsize) : ($ypos+(4*$fsize)), ($t_current > 0) ? $black : $red, $font, $t_unit."$t_current"); // Current < Max
}
}
}
if ($t_current > $t_max) {
$burstImg = ImageCreateFromjpeg('burst.jpg');
$burstW = ImageSX($burstImg);
$burstH = ImageSY($burstImg);
ImageCopy($finalimage, $burstImg, 0,0,0,0,$burstW, $burstH);
}
Imagejpeg($finalimage);
Imagedestroy($finalimage);
Imagedestroy($thermImage);
Imagedestroy($thermbarImage);
?>

html snippet:
<!-- BEGIN THERMOMETER -->
<span class="Text3">Annual Savings Goals</span><br><br><­/td>
<td width="266" height="300" rowspan="2" align="center">
<img alt='Solantic Cost Savings Progress Thermometer' src="http://webserv:81/the...­
</font>

</td>
</tr>
<tr>
<td width="440" height="300" align="left" valign="top">
<table border="0" cellpadding="0" cellspacing="0" width="425">
<tbody><tr>
<td class="Text4" style="padding-right: 10px;" align="left" width="228" height="25">&nbsp;&nbsp;­&nbsp;&nbsp;&nbsp;• &nbsp;&nbsp;Target Cost:</td>
<td width="15" height="25" align="center" class="Text5">$ </td>
<td width="194"><input id="max" name="max" size="25" maxlength="25" type="text"></td>
</tr>
<tr>
<td class="Text4" style="padding-right: 10px;" align="left" width="228">&nbsp;&nbsp;­&nbsp;&nbsp;&nbsp;• &nbsp;&nbsp;Amount Saved To Date: </td>
<td align="center" class="Text5">$ </td>
<td><input id="current" name="current" size="25" maxlength="25" type="text"></td>
</tr>
<tr>
<td class="Text4" style="padding-right: 10px;" align="left" width="228">&nbsp;&nbsp;­&nbsp;&nbsp;&nbsp;• &nbsp;&nbsp;% of Goal Achieved: </td>
<td align="center" class="Text5">% </td>
<td><input name="total1" id="total1" size="25" maxlength="5" type="text"></td>
</tr>
<tr>
<td class="Text4" style="padding-right: 10px;" align="left" width="228">&nbsp;&nbsp;­&nbsp;&nbsp;&nbsp;• &nbsp;&nbsp;Amount Remaining:</td>
<td align="center" class="Text5">$ </td>
<td><input name="Total2" id="total2" size="25" maxlength="5" type="text"></td>
</tr>
<tr>
<td class="Text4" style="padding-right: 10px;" align="left" width="228">&nbsp;&nbsp;­&nbsp;&nbsp;&nbsp;• &nbsp;&nbsp;% of Goal Remaining:</td>
<td align="center" class="Text5">% </td>
<td><input name="Total3" id="total3" size="25" maxlength="5" type="text"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td colspan="2">
&nbsp;&nbsp; </td>
</tr>
<tr>
<td width="228"><span class="Text4" style="padding-right: 10px;"><span class="Text4" style="padding-right: 10px;"><span class="Text4" style="padding-right: 10px;"><span class="Text4" style="padding-right: 10px;"><span class="Text4" style="padding-right: 10px;"><span class="Text4" style="padding-right: 10px;"><span class="Text4" style="padding-right: 10px;"><span class="Text4" style="padding-right: 10px;">
&nbsp;&nbsp;&nbsp;&nbsp;­&nbsp; </span></span></span><­/span></span></span></­span></span></td>
<td colspan="2" align="left"><input class="button" name="apply" value="Update Thermometer" onClick="fadd()" type="button"></td>
</tr>

Any help would be appreciated.
-Bill
A former member
Post #: 109
What are you using to test this as I see you have a local font configured. I believe i have the answer but I need to know if you are using wampserver or something like that. Just let you know the above script works for me though I did need to download for the proper initial images.

A former member
Post #: 110
My guess would be the automatic configuration of PHP for wampserver. You may need to go into the PHP.ini file and uncomment extension=php_mbstring.dll extension=php_exif.dll. Next you will need to move extension=php_exif.dll below extension=php_mbstring.dll as mbstring.dll is required for exif.dll as the php install orders them by ABC this does not work! Next, Save the PHP.ini and stop and restart the server! It should work now.




Tim
ZipOnOver, Local business tools
A former member
Post #: 2
Tim,

Thank you for your reply, I tried your fix and the graphic is still not updating. I am running on a windows server with a manual install of both apache and php-5. I have a laptop with LAMP on it, I am going to try it on there to see if it works. Any other ideas?

Thanks!

-Bill
A former member
Post #: 111
One thing I did not mention as it is normally active as default is GD as in extension=php_gd2.dll

Image Processing and Generation

What is happening is an image is being created with the therm.jpg as the background then takes the thermbar.jpg and increments it over the area as it increases to the goal and the burst image over the top once you pass the goal. this is done with the help of the gd2, exif and mbstring extensions. If you are just not seeing the bar go up.

If not getting the POST data to the script, make sure you are using POST method.
<form action="index.php" method="POST" name="FormName" target="">
<input type="text" name="current" size="5" maxlength="5" value="">
<input type="hidden" name="unit" value="36">
<input type="hidden" name="max" value="100">
<input type="submit" value="SUBMIT"></form>­
$unit is just the dollar symbol and would be easier just to hard code.

wampserver is about the best option for a wamp environment and works straight from the install. still need to do as in previous post to get image creation to work as I had to figure why a captcha was not working. The wampserver just provides real easy configuration!
Apache, MySQL, PHP on Windows

I think I would of used imageline() to create the mercury as could allow a more accurate representation of the current value, or stretched the thermbar.jpg's height.

Tim
A former member
Post #: 3
Tim,

Thank you so much for taking the time to respond, I believe you are right on with the POST data not showing up. I will check this out tomorrow when I get in and post the results.

Cheers,
-Bill
Eric N.
user 4016762
Group Organizer
Orange Park, FL
Post #: 75
Tim,

Thank you for your reply, I tried your fix and the graphic is still not updating. I am running on a windows server with a manual install of both apache and php-5. I have a laptop with LAMP on it, I am going to try it on there to see if it works. Any other ideas?

Thanks!

-Bill

Bill,

I don't know my way around WAMP like Tim, but you may face similar issues re graphic libraries on your laptop, depending on your distro and how your LAMP server was set up.

(If you get the graphics to work in LAMP, but not the text, you may be missing TrueType fonts.)

Eric
Powered by mvnForum

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy