Mouse Posted August 24, 2006 Share Posted August 24, 2006 Donations thermometer Ladies and gentlemen… good day to you all.Well its my least favourite subject here… math(s). to be honest it’s the bit in PHP I suck at… and the other bit I know nothing of is graphics in PHP.What I am aiming to do is generate a horizontal donations thermometer on my site. I think the community site I am building will benefit so here’s what I am aiming to do… To produce an image X pixels high, by Y pixels wide that will represent the part of the target amount (lets call it Z), which has been met by donations (erm… lets call that D).So far I got to here (#### ) and lost the will to live (if life involves maths that is…)[code]<?// Add values to the graph$graphValues=10; // D for Donations random ammount for testing// Define .PNG imageheader("Content-type: image/png");$imgWidth=300; // Y pixels wide$imgHeight=10; // X pixels high// Create image and define colors$image=imagecreate($imgWidth, $imgHeight);$colorWhite=imagecolorallocate($image, 255, 255, 255); // Background Colour$colorBlue=imagecolorallocate($image, 104, 157, 228); // Border Colour$colorRed=imagecolorallocate($image, 255, 51, 0); // Thermomiter Fill Colour########################################// Output graph and clear image from memoryimagepng($image);imagedestroy($image);?>[/code]If any kind Math / PHP fiend would care to help I would be gratefulMany thanksMouse Link to comment https://forums.phpfreaks.com/topic/18562-donations-thermometer-graphics-meets-maths-meets-grrrrrrrr/ Share on other sites More sharing options...
AdRock Posted August 24, 2006 Share Posted August 24, 2006 I don't know if this is any good but I got this fund raising thermoter for my site here[url=http://www.entropyfarm.org/software/thermo/]http://www.entropyfarm.org/software/thermo/[/url]I changed some of the sizes of the images and changed some of the variables to make it fit within my site and it does the job i want Link to comment https://forums.phpfreaks.com/topic/18562-donations-thermometer-graphics-meets-maths-meets-grrrrrrrr/#findComment-79948 Share on other sites More sharing options...
Mouse Posted August 25, 2006 Author Share Posted August 25, 2006 [quote author=AdRock link=topic=105508.msg421498#msg421498 date=1156441531]I don't know if this is any good but I got this fund raising thermoter for my site here[url=http://www.entropyfarm.org/software/thermo/]http://www.entropyfarm.org/software/thermo/[/url]I changed some of the sizes of the images and changed some of the variables to make it fit within my site and it does the job i want[/quote]most excelent... why didn't i find this... many thanks Link to comment https://forums.phpfreaks.com/topic/18562-donations-thermometer-graphics-meets-maths-meets-grrrrrrrr/#findComment-80193 Share on other sites More sharing options...
Barand Posted August 25, 2006 Share Posted August 25, 2006 Your image width is 300px, but you need to know what value the full width represents (ie what is your max value);Assuming it's 100,$max = 100;$graph_value = 10;$valWidth = ($graph_value/$max) * 300;imagefilledrectangle($im, 0, 0, $valWidth , $imageHeight, $colorRed);imagerectangle ($im, 0, 0, $imgWidth - 1, $imageHeight - 1, $colorBlue); Link to comment https://forums.phpfreaks.com/topic/18562-donations-thermometer-graphics-meets-maths-meets-grrrrrrrr/#findComment-80218 Share on other sites More sharing options...
Mouse Posted August 25, 2006 Author Share Posted August 25, 2006 [quote author=Barand link=topic=105508.msg421796#msg421796 date=1156489658]Your image width is 300px, but you need to know what value the full width represents (ie what is your max value);Assuming it's 100,$max = 100;$graph_value = 10;$valWidth = ($graph_value/$max) * 300;imagefilledrectangle($im, 0, 0, $valWidth , $imageHeight, $colorRed);imagerectangle ($im, 0, 0, $imgWidth - 1, $imageHeight - 1, $colorBlue);[/quote]Many thanks i'll give this a spin tonight when i get 127.0.0.1 many thanksMouse Link to comment https://forums.phpfreaks.com/topic/18562-donations-thermometer-graphics-meets-maths-meets-grrrrrrrr/#findComment-80220 Share on other sites More sharing options...
Mouse Posted August 25, 2006 Author Share Posted August 25, 2006 "The image “http://localhost/atm-v5/thermo.php” cannot be displayed, because it contains errors." Hmmm... needs work (note to self: maybe i should just do this in photoshop...!)Any One?Mouse Link to comment https://forums.phpfreaks.com/topic/18562-donations-thermometer-graphics-meets-maths-meets-grrrrrrrr/#findComment-80469 Share on other sites More sharing options...
AdRock Posted August 25, 2006 Share Posted August 25, 2006 Try emailing the person who wrote it. They may be able to help.Is the GD graphics library working ok? Does it say what errors. it too me a couple attempts to get it working but it does work....look at http://www.jackgodfrey.org.uk Link to comment https://forums.phpfreaks.com/topic/18562-donations-thermometer-graphics-meets-maths-meets-grrrrrrrr/#findComment-80476 Share on other sites More sharing options...
dark dude Posted August 25, 2006 Share Posted August 25, 2006 [quote author=Mouse link=topic=105508.msg422088#msg422088 date=1156539630]"The image “http://localhost/atm-v5/thermo[b][color=red].php[/color][/b]” cannot be displayed, because it contains errors." Hmmm... needs work (note to self: maybe i should just do this in photoshop...!)Any One?Mouse[/quote]I dont believe images use the .php extension ;)Php = Script extension, an Image extension = .gif, .jpg, .png, .tif, .bmp, .psd etc Link to comment https://forums.phpfreaks.com/topic/18562-donations-thermometer-graphics-meets-maths-meets-grrrrrrrr/#findComment-80483 Share on other sites More sharing options...
AdRock Posted August 25, 2006 Share Posted August 25, 2006 This srcipt uses small images to give the impression that the thermoter moves depending on the variable values Link to comment https://forums.phpfreaks.com/topic/18562-donations-thermometer-graphics-meets-maths-meets-grrrrrrrr/#findComment-80486 Share on other sites More sharing options...
AndyB Posted August 25, 2006 Share Posted August 25, 2006 Barand's script .. with a couple of edits so variable names match, etc. Works perfectly.[code]<?php// Define .PNG imageheader("Content-type: image/png");$imgWidth=300; // Y pixels wide$imgHeight=10; // X pixels high// Create image and define colors$image=imagecreate($imgWidth, $imgHeight);$colorWhite=imagecolorallocate($image, 255, 255, 255); // Background Colour$colorBlue=imagecolorallocate($image, 104, 157, 228); // Border Colour$colorRed=imagecolorallocate($image, 255, 0, 0); // Fill Colour$max = 100;$graph_value = 10;$valWidth = ($graph_value/$max) * 300;imagefilledrectangle($image, 0, 0, $valWidth , $imgHeight, $colorRed);imagerectangle ($image, 0, 0, $imgWidth - 1, $imgHeight - 1, $colorBlue);// Output graph and clear image from memoryimagepng($image);imagedestroy($image);?>[/code] Link to comment https://forums.phpfreaks.com/topic/18562-donations-thermometer-graphics-meets-maths-meets-grrrrrrrr/#findComment-80493 Share on other sites More sharing options...
Barand Posted August 25, 2006 Share Posted August 25, 2006 Here's the one I usually use, passing max and val as variables:: bar.php ::[code]<?php// set dimensions $w = 300; $h = 12;// create image $im = imagecreate($w, $h);// set colours to be used $bg = imagecolorallocate($im, 0xE0, 0xE0, 0xE0); $black = imagecolorallocate($im, 0x00, 0x00, 0x00); $barcolor = imagecolorallocate($im, 0xFF, 0xFF, 0x00);// draw border imagerectangle($im, 0,0,$w-1,$h-1,$black);// get value and max value from query string $val = $_GET['val']; $max = $_GET['max'];// calculate dimensions of inner bar $barw = $max ? floor(($w-2) * $val / $max) : 0; $barh = $h - 2;// draw inner bar if ($barw) imagefilledrectangle($im, 1, 1, $barw, $barh, $barcolor);// send image header header("content-type: image/png");// send png image imagepng($im); imagedestroy($im);?>[/code]Place on page with[code]<img src='bar.php?val=30&max=100'>[/code]Dark_Dude: Note the .php extension for a dynamicaly produced image Link to comment https://forums.phpfreaks.com/topic/18562-donations-thermometer-graphics-meets-maths-meets-grrrrrrrr/#findComment-80499 Share on other sites More sharing options...
Mouse Posted August 26, 2006 Author Share Posted August 26, 2006 AndyB, Barand... Gentlemen and scholars both!thanks chaps.... Link to comment https://forums.phpfreaks.com/topic/18562-donations-thermometer-graphics-meets-maths-meets-grrrrrrrr/#findComment-80771 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.