<?php
/*
********************************************************************************************
* x jeremy jarratt coded this terribly didn't he - http://jeremyjarratt.com/ - @transmothra
* PRAISE DOBBS! HAIL ERIS! ALL HAIL DISCORDIA!
* This work is licensed under the
* Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/.
********************************************************************************************
*/
// EDIT THESE NEXT FEW LINES
// set your timezone or suffer the consequences
date_default_timezone_set('America/New_York');
// set your quit date
$quitdate = "2010-08-16"; // change this to your quit date
// how much is a pack of smokes worth where you live?
$cigprice = 5.00; // omit the dollar sign
// how many packs per day did you smoke?
$packsperday = 2.5; // decimals ok
// how much do you spend on vaping per month?
$vapecostmonthly = 30; // omit the dollar sign
// set your font by filename - UPLOAD YOUR FONT FILE TO THE SAME DIRECTORY
$font = './trebuc.ttf';
$fontb = './trebucbd.ttf';
// number of pixels for the left margin
$left_margin = 5;
// HEY LET'S CALCULATE A BUNCH OF CRAP (in general, leave this alone)
$now = time(); // this is really NOW, for comparison to your quit date
$your_date = strtotime($quitdate);
$datediff = $now - $your_date; // compare your quit date to right now (output in seconds)
$datetime1 = new DateTime($quitdate);
$datetime2 = new DateTime();
$interval = date_diff($datetime1, $datetime2); // just another time comparison
$howlong = $interval->format('%y years, %m months, %d days');
$vapedays = floor($datediff/(60*60*24)); // convert time since quitting to days (rounded down to eliminate any remainder)
$vapecostdaily = $vapecostmonthly/30; // divide monthly cost by 30 for a daily cost
$vapecost_ttl = $vapecostdaily*$vapedays; // multiply daily vape cost by total days since quitting
$vapesaved = $vapedays*$cigprice*$packsperday-$vapecost_ttl; // days x cost x ppd, minus vaping costs
$cigsavoided = $packsperday*20*$vapedays; // ppd x 20 smokes per pack x total days since quitting
$packs = $cigsavoided/20; // total number of packs avoided since quitting
// format numbers: decimal places, decimal separator, thousands separator
$vapesaved = number_format($vapesaved, 2, '.', ',');
$vapecost_ttl = number_format($vapecost_ttl, 2, '.', ',');
$cigsavoided = number_format($cigsavoided, 0, '.', ',');
$packs = number_format($packs, 0, '.', ',');
$vapedays = number_format($vapedays, 0, '.', ',');
// put in a bunch of quotes or whatever you want; space is limited!; rotated on a random basis
$randomquote = array(
'How can I be free in the shadow of a chapel? (anon)',
'We are a way for the cosmos to know itself. (C.Sagan)',
'I\'d take the awe of understanding over the awe of ignorance any day. (D.Adams)',
'I love deadlines. I love the whooshing noise they make as they go by. (D.Adams)',
'DON\'T PANIC (D.Adams)',
'Nothing is true. Everything is permissible. (Hassan i Sabbah)',
'Curb Your Dogma. (Hill/Thornley)',
'The Enlightened take things Lightly. (Hill/Thornley)',
'Ideologies separate us. Dreams and anguish bring us together. (Ionesco)',
'Anyone who isn\'t confused doesn\'t really understand the situation. (E.Murrow)',
'As for me, all I know is that I know nothing. (Socrates)',
'Only the madman is absolutely sure. (RA Wilson)',
'A frog in a well cannot conceive of the ocean. (Zhuangzi)',
'With our thoughts we make the world. (Gotama)',
'Oppressive laws don\'t destroy minorities; they simply make bootleggers. (HL Mencken)',
'Nature abhors a moron. (HL Mencken)',
'Puritanism: The haunting fear that someone, somewhere, may be happy. (HL Mencken)',
'The highest understanding we can achieve: laughter & human compassion. (Feynman)',
);
$quotation = $randomquote[rand(0, sizeof($randomquote) - 1)];
// DON'T EDIT UNLESS YOU KNOW WHAT YOU'RE DOING
$image = 'signature_bar.png'; // create a banner image with this name; 468 pixels wide by 60 pixels tall
$im = imagecreatefrompng($image);
// set colors (RGB)
$main_color = imagecolorallocate($im, 51, 102, 153);
$black = imagecolorallocate($im, 0, 0, 0);
$orange = imagecolorallocate($im, 255, 140, 0);
$blue = imagecolorallocate($im, 216, 196, 255);
$red = imagecolorallocate($im, 255, 0, 0);
$green = imagecolorallocate($im, 0, 160, 0);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 216, 216, 216);
$yellow = imagecolorallocate($im, 255, 216, 64);
/* OUTPUT FOR TESTING/DEBUGGING - TO TEST, COMMENT OUT EVERYTHING BELOW THIS BLOCK TO THE END
echo "now = ".$now."<br>".
"quitdate = ".$quitdate."<br>".
"your_date = ".$your_date."<br>".
"datediff = ".$datediff."<br>".
"howlong = ".$howlong."<br>".
"vapedays = ".$vapedays."<br>".
"vapesaved = ".$vapesaved."<br>".
"cigsavoided = ".$cigsavoided."<br>".
"packs = ".$packs."<br>"
;
*/
// THE MAGIC: set font size, font angle, horizontal position, vertical position, color, fontface, text
// Add the text - drop shadow
imagettftext($im, 12, 0, $left_margin-2, 18, $black, $fontb, 'Vaping since 16 August 2010; '.$howlong);
imagettftext($im, 10, 0, $left_margin-2, 34, $black, $font, 'Cigarettes avoided: '.$cigsavoided.' in '.$packs.' packs');
imagettftext($im, 10, 0, $left_margin-2, 50, $black, $font, 'Money spent on better things: $'.$vapesaved);
imagettftext($im, 8, 0, $left_margin-1, 65, $black, $fontb, $quotation);
// Add the text
imagettftext($im, 12, 0, $left_margin, 16, $orange, $fontb, 'Vaping since 16 August 2010; '.$howlong);
imagettftext($im, 10, 0, $left_margin, 32, $blue, $font, 'Cigarettes avoided: '.$cigsavoided.' in '.$packs.' packs');
imagettftext($im, 10, 0, $left_margin, 48, $white, $font, 'Money spent on better things: $'.$vapesaved.' ($'.$vapecost_ttl.' of that vaped)');
imagettftext($im, 8, 0, $left_margin, 64, $yellow, $fontb, $quotation);
// LEAVE THESE ALONE DAMN YOU
header('Content-Disposition: filename=signature_bar.png');
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>