Solved

PHP Fund thermometer

Posted on 2014-09-04
4
384 Views
Last Modified: 2014-09-04
Hello experts,

Have anyone use the PHP Fundraising Thermometer: http://sourceforge.net/projects/phpfundthermo/

I tried to create the thermometer, but I am just getting the source code on the screen.
Can someone please help?

Thanks.
0
Comment
Question by:lgduong
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40304058
If you are seeing the source code that means your server doesn't understand PHP or you are not running the page through a server.
How are you loading the page in the browser? What server are you using?
0
 

Author Comment

by:lgduong
ID: 40304205
I am running on an Apache server and I have created multiple php pages and are able to view the results of the php.  I am viewing it via Firefox on the web server that I do with my other pages.  Not sure what it is giving me problem.  Here is the code:
<?
/*
     Fundraising Thermometer Generator v1.1
     Sairam Suresh sai1138@yahoo.com / www.entropyfarm.org
    
     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&63)+128);
 if ($num<65536) return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128);
 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";
$font = $_SERVER['DOCUMENT_ROOT']."/fonts/arial.ttf";

$unit = ($_REQUEST['unit']) ? $_REQUEST['unit'] : 36; // ascii 36 = $
die($unit);
$t_unit = ($unit == 'none') ? '' : code2utf($unit);
$t_max = ($_REQUEST['max']) ? $_REQUEST['max'] : 0;
$t_current = isset($_REQUEST['current']) ? $_REQUEST['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.rosiehardman.com/

$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);

?> 

Open in new window

0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40304224
You don't have short open tags enabled so
<?

will not work, you will need to change it to
<?php

Bad coding on their part
0
 

Author Comment

by:lgduong
ID: 40304234
I can not believe I missed that.  It is those little syntax that will throw me up.  Thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
This video teaches users how to migrate an existing Wordpress website to a new domain.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question