<?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/Chicago');
// set your quit date
$quitdate = "2014-04-29 22:00:00"; // change this to your quit date
// how much is a pack of smokes worth where you live?
$cigprice = 7.20; // omit the dollar sign
// how many packs per day did you smoke?
$packsperday = 1.5; // decimals ok
// how much do you spend on vaping per month?
$vapecostmonthly = 30; // omit the dollar sign
// how many mL per day?
$ml = 6; // omit units
// what nicotine strength in mg/mL?
$mg = 3; // omit units
$juice = 'DIY';
// set your font by filename - UPLOAD YOUR FONT FILE TO THE SAME DIRECTORY
$font = './fonts/tt0142m_.ttf';
$fontb = './fonts/tt0144m_.ttf';
// HEY LET'S CALCULATE A BUNCH OF CRAP (in general, leave this alone)
$prettydate = date_create_from_format("Y-m-j H:i:s", $quitdate); // no, not a girl/boy. just a nicer-looking date format.
$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, %h hours, %i minutes, %s seconds');
$vapedays = floor($datediff/(60*60*24)); // convert time since quitting to days (rounded down to eliminate any remainder)
$vapedayspre = $datediff/(60*60*24);
$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; // days x cost x ppd, minus vaping costs
$cigsavoided = floor($packsperday*20*$vapedayspre); // 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, '.', ',');
$cigsavoided = number_format($cigsavoided, 0, '.', ',');
$packs = number_format($packs, 0, '.', ',');
$vapedays = number_format($vapedays, 0, '.', ',');
// messages (save some typing and avoid formatting errors)
$cigline = $cigsavoided.' analogs avoided in the '.$vapedays.' days since '.date_format($prettydate, 'F j, Y').' ('.$packs.' packs).';
$moneyline = '$'.$vapesaved.' saved, of which $'.$vapecost_ttl.' was shamelessly vaped.';
$ml = $ml.'mL/day';
$mg = $mg.'mg/mL';
/*
// put in a bunch of quotes or whatever you want; space is limited!; rotated on a random basis
$randomquote = array(
'The SubGenius must have SLACK! (B.Dobbs)',
'Hail Eris! All Hail Discordia!',
'How can I be free in the shadow of a chapel? (anon)',
'Act like a dumbshit and they\'ll treat you like an equal (B.Dobbs)',
'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 = './images/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, 100, 100, 255);
$red = imagecolorallocate($im, 212, 48, 52);
$green = imagecolorallocate($im, 0, 160, 0);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 216, 216, 216);
$yellow = imagecolorallocate($im, 255, 216, 64);
// the spacing
$line1vert = 16;
$line2vert = 32;
$line3vert = 48;
// number of pixels for the left margin
$left_margin = 5;
$far_margin = 430;
// THE MAGIC: set font size, font angle, horizontal position, vertical position, color, fontface, text
// Add the text - drop shadow
imagettftext($im, 10, 0, $left_margin-2, $line1vert+2, $black, $fontb, $howlong);
imagettftext($im, 8, 0, $left_margin-2, $line2vert+2, $black, $font, $cigline);
imagettftext($im, 8, 0, $left_margin-2, $line3vert+2, $black, $font, $moneyline);
imagettftext($im, 6, 0, $far_margin-2, $line1vert+2, $black, $font, $ml);
imagettftext($im, 6, 0, $far_margin-2, $line2vert+2, $black, $font, $mg);
imagettftext($im, 6, 0, $far_margin-2, $line3vert+2, $black, $font, $juice);
//imagettftext($im, 8, 0, $left_margin-1, 65, $black, $fontb, $quotation);
// Add the text
imagettftext($im, 10, 0, $left_margin, $line1vert, $red, $fontb, $howlong);
imagettftext($im, 8, 0, $left_margin, $line2vert, $white, $font, $cigline);
imagettftext($im, 8, 0, $left_margin, $line3vert, $white, $font, $moneyline);
imagettftext($im, 6, 0, $far_margin, $line1vert, $white, $font, $ml);
imagettftext($im, 6, 0, $far_margin, $line2vert, $white, $font, $mg);
imagettftext($im, 6, 0, $far_margin, $line3vert, $white, $font, $juice);
//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);
?>