Example #1
0
function generateImage($image, $username, $hour, $min, $sec, $distance, $texts, $filename)
{
    $path = $filename ? BASE_PATH . '/uploads/' . $filename : '';
    $img = new textPainter(BASE_PATH . '/assets/images/' . $image, '', BASE_PATH . '/assets/fonts/Memphis-ExtraBold.ttf', 20, $path);
    $img->setQuality(100);
    $img->addText($username, 54, 80, BASE_PATH . '/assets/fonts/memphisltstd-light-webfont.ttf', 25, 255, 255, 255);
    $img->addText($hour, 440, 405, BASE_PATH . '/assets/fonts/Memphis Medium.ttf', 18, 255, 255, 255);
    $img->addText($min, 485, 405, BASE_PATH . '/assets/fonts/Memphis Medium.ttf', 18, 255, 255, 255);
    $img->addText($sec, 530, 405, BASE_PATH . '/assets/fonts/Memphis Medium.ttf', 14, 255, 255, 255);
    $img->addText($distance, 670, 405, BASE_PATH . '/assets/fonts/Memphis Medium.ttf', 20, 255, 255, 255);
    $img->addText('KM', 750, 395, BASE_PATH . '/assets/fonts/Memphis Medium.ttf', 10, 255, 255, 255);
    if ($texts) {
        foreach ($texts as $text) {
            $img->addText($text[0], $text[1], $text[2], $text[3], $text[4], $text[5], $text[6], $text[7]);
        }
    }
    $img->show();
}
// Convert strings from stats file to integers.
$threes = intval($threes);
$threes_attempted = intval($threes_attempted);
$games = intval($games);
// Compute pace and round down.
$pace = floatval($threes / $games * 82);
$pace = round($pace, 0, PHP_ROUND_HALF_DOWN);
// Compute 3pt% and round to nearest tenth.
$pct = floatval($threes / $threes_attempted * 100);
$pct = round($pct, 1, PHP_ROUND_HALF_DOWN);
$img = new textPainter('static/img/currycardbg.png', '', 'static/fonts/font.ttf', 80);
// Grey
$img->setTextColor(160, 160, 160);
$img->setText('THREES', 472, 84, 50);
$img->setText('GAMES', 472, 154, 55);
$img->setText('PACE', 566, 208, 42);
$img->setText('3PT%', 566, 257, 36);
$img->setText('www.scthrees.com', 592, 383, 16);
$img->setText('#curry3count', 634, 359, 16);
// White
$img->setTextColor(255, 255, 255);
$img->setText($threes, 688, 84, 50);
$img->setText($games, 688, 154, 55);
$img->setText($pct, 688, 257, 36);
$img->setText('Stephen Curry', 587, 311, 21.38);
$img->setText('2015-2016   3pt   stats', 587, 335, 16);
// Warriors yellow
$img->setTextColor(251, 220, 5);
$img->setText($pace, 688, 208, 42);
$img->setQuality(100);
$img->show();