Ejemplo n.º 1
0
// Display canvas as png image when php page is requested.
if (!$metrics) {
    header("Content-Type: image/" . IMGFMT);
    echo $canvas;
}
// Generate thumbnail image of the title for UI purposes.
$thumb = $canvas->clone();
if ($player) {
    $thumb->cropImage(427, 240, 350, 795);
    $thumb->resizeImage(72, 40, Imagick::FILTER_TRIANGLE, 1);
    $thumb->writeImage(realpath('thumbs') . '/' . $filename . '.' . IMGFMT);
    // headshotless title generation for animation
    $noHeadshot = getStatscard($player, ["emptyHeadshot" => true]);
    $noHeadshotCanvas = new Imagick();
    $noHeadshotCanvas->newImage(1920, 1080, "none", IMGFMT);
    $noHeadshotCanvas->setImageDepth(8);
    $noHeadshotCanvas->setimagecolorspace(imagick::COLORSPACE_SRGB);
    foreach ($noHeadshot['geos'] as $geo) {
        addGeoToCanvas($noHeadshotCanvas, $geo, $bustCache);
    }
    $noHeadshotCanvas->writeImage(realpath('out') . '/' . $filename . '_noHeadshot.' . IMGFMT);
} else {
    //$thumb->cropImage(1440, 1080, 0, 0);
    $thumb->resizeImage(72, 40, Imagick::FILTER_TRIANGLE, 1);
    $thumb->writeImage(realpath('thumbs') . '/' . $filename . '.' . IMGFMT);
}
timestamp('post thumbs');
// Generate the output file of the title.
$canvas->writeImage(realpath('out') . '/' . $filename . '.' . IMGFMT);
dbquery("REPLACE INTO cache SET `key`='{$key}', `hash`='" . getHashForTitle($title) . "';");
timestamp('post out');
Ejemplo n.º 2
0
function flexBox(&$canvas, $o, $bustCache = false)
{
    $logoHeight = 0;
    $logoHeightDiff = 0;
    $logoXAdjust = 0;
    if (($o['logoLeft'] || $o['logoRight']) && $o['logoHeight'] > 0) {
        $logoHeight = $o['logoHeight'];
        $logoHeightDiff = ($logoHeight - $o['titleHeight']) / 2;
        $logoHeightDiff -= $o['subTitleHeight'];
        $logoHeightDiff = $logoHeightDiff > 0 ? $logoHeightDiff : 0;
        $logoXAdjust = $logoHeight * 1.5;
    }
    $pad = 15;
    $bottom = 50;
    $geos = array();
    $text = $o['bodyText'];
    $text = str_replace('\\n', PHP_EOL, $text);
    $lines = substr_count($text, PHP_EOL) + 1;
    $textBoxHeight = $o['boxHeight'] > 0 ? $o['boxHeight'] : $lines * $o['lineHeight'];
    $boxHeight = $textBoxHeight + $o['titleHeight'] + $o['subTitleHeight'] + $pad + $logoHeightDiff;
    $boxWidth = $o['boxWidth'];
    $boxX = $o['boxOffset'] > 0 ? $o['boxOffset'] : (1920 - $boxWidth) / 2;
    $boxY = 1080 - $boxHeight - $bottom;
    //
    // Main Black Box
    //
    $geos[] = array('type' => 'blackBox', 'x' => $boxX, 'y' => $boxY, 'w' => $boxWidth, 'h' => $boxHeight);
    //
    // Body Text
    //
    $geos[] = array('type' => 'plainText', 'font' => 'fontN', 'gravity' => 'west', 'text' => $o['bodyText'], 'color' => 'white', 'x' => $boxX + $pad, 'y' => 1080 - $textBoxHeight - $bottom, 'w' => $boxWidth - $pad * 2, 'h' => $textBoxHeight, 'wordWrap' => $lines > 1 ? false : true);
    //
    // Sub Title Bar
    //
    $subTitleWidth = $o['subTitleWidth'];
    if ($subTitleWidth < 0) {
        $subTitleWidth = $boxWidth + $o['titleHeight'] + $o['subTitleWidth'];
    }
    $subTitleX = (1920 - $subTitleWidth) / 2;
    $geos[] = array('type' => 'slantRectangle', 'x' => $subTitleX, 'y' => 1080 - $boxHeight - $bottom + $o['titleHeight'], 'w' => $subTitleWidth, 'h' => $o['subTitleHeight'], 'color' => $o['subTitleColor']);
    //
    // Title Bar
    //
    $geos[] = array('type' => 'slantRectangle', 'x' => $boxX - $o['titleHeight'] / 2, 'y' => 1080 - $boxHeight - $bottom, 'w' => $boxWidth + $o['titleHeight'], 'h' => $o['titleHeight'], 'color' => $o['titleColor']);
    $barTextPad = 3;
    if ($o['subTitleHeight'] > 0) {
        $geos[] = array('type' => 'shadowText', 'font' => 'fontN', 'gravity' => 'center', 'text' => $o['subTitleText'], 'color' => 'white', 'x' => $subTitleX + $o['subTitleHeight'] / 2, 'y' => 1080 - $boxHeight - $bottom + $o['titleHeight'] + $barTextPad, 'w' => $subTitleWidth - $o['subTitleHeight'], 'h' => $o['subTitleHeight'] - $barTextPad * 2);
    }
    $titleXAdjust = 0;
    $titleWAdjust = 0;
    $logoY = 1080 - $boxHeight - $bottom - ($logoHeight - $o['titleHeight']) / 2;
    //
    // Left Logo
    //
    if ($o['logoLeft'] && $logoHeight) {
        $geos[] = array('type' => 'slantRectangle', 'color' => 'white', 'x' => $boxX - $logoHeight / 2, 'y' => $logoY, 'w' => $logoHeight * 2, 'h' => $logoHeight);
        $geos[] = array('type' => 'placeImage', 'path' => $o['logoLeft'], 'x' => $boxX, 'y' => $logoY - 2, 'w' => $logoHeight, 'h' => $logoHeight, 'shadow' => '5', 'padding' => '9');
        $titleXAdjust = $titleWAdjust = $logoXAdjust;
    }
    //
    // Right Logo
    //
    if ($o['logoRight'] && $logoHeight) {
        $geos[] = array('type' => 'slantRectangle', 'color' => 'white', 'x' => $boxX + $boxWidth - $logoHeight * 1.5, 'y' => $logoY, 'w' => $logoHeight * 2, 'h' => $logoHeight);
        $geos[] = array('type' => 'placeImage', 'path' => $o['logoRight'], 'x' => $boxX + $boxWidth - $logoHeight, 'y' => $logoY - 2, 'w' => $logoHeight, 'h' => $logoHeight, 'shadow' => '5', 'padding' => '9');
        $titleWAdjust += $logoXAdjust;
    }
    $geos[] = array('type' => 'shadowText', 'font' => 'fontN', 'gravity' => $o['titleGravity'], 'text' => $o['titleText'], 'color' => 'white', 'x' => $boxX + $titleXAdjust, 'y' => 1080 - $boxHeight - $bottom + $barTextPad, 'w' => $boxWidth - $titleWAdjust, 'h' => $o['titleHeight'] - $barTextPad * 2);
    //echo '<pre>'; print_r($geos);
    foreach ($geos as $geo) {
        addGeoToCanvas($canvas, $geo);
    }
    //return $localCanvas;
}
Ejemplo n.º 3
0
<?php

include 'include.php';
include 'imagick_include.php';
$deets = array('x' => 20, 'y' => 20, 'color' => 'red', 'h' => 60, 'type' => 'slantRectangle');
$start = 50;
$end = 1000;
$step = ($end - $start) / 60;
for ($i = 0; $i < 60; $i++) {
    $canvas = new Imagick();
    $canvas->newImage(1050, 100, "none", "png");
    $canvas->setImageDepth(8);
    $geo = $deets;
    $geo['w'] = $start + $i * $step;
    $geo['x'] = ($end - $geo['w']) / 2;
    addGeoToCanvas($canvas, $geo);
    $file = '/bar' . sprintf('%03d', $i) . '.png';
    $canvas->writeImage(realpath('anim') . $file);
    echo '<img src="anim' . $file . '" />';
    flush();
}
Ejemplo n.º 4
0
function weather(&$canvas, $o, $bustCache = true)
{
    $logoHeight = 0;
    $logoHeightDiff = 0;
    $logoXAdjust = 0;
    if (($o['logoLeft'] || $o['logoRight']) && $o['logoHeight'] > 0) {
        $logoHeight = $o['logoHeight'];
        $logoHeightDiff = ($logoHeight - $o['titleHeight']) / 2;
        $logoHeightDiff -= $o['subTitleHeight'];
        $logoHeightDiff = $logoHeightDiff > 0 ? $logoHeightDiff : 0;
        $logoXAdjust = $logoHeight * 1.5;
    }
    $pad = 15;
    $bottom = 50;
    $geos = array();
    $text = $o['bodyText'];
    $text = str_replace('\\n', PHP_EOL, $text);
    $lines = substr_count($text, PHP_EOL) + 1;
    $textBoxHeight = $o['boxHeight'] > 0 ? $o['boxHeight'] : $lines * $o['lineHeight'];
    $boxHeight = $textBoxHeight + $o['titleHeight'] + $o['subTitleHeight'] + $pad + $logoHeightDiff;
    $boxWidth = $o['boxWidth'] - 100;
    $boxX = $o['boxOffset'] > 0 ? $o['boxOffset'] : (1920 - $boxWidth) / 2;
    $boxY = 1080 - $boxHeight - $bottom;
    // Main Black Box
    $geos[] = array('type' => 'blackBox', 'x' => $boxX, 'y' => $boxY, 'w' => $boxWidth, 'h' => $boxHeight);
    // Body Text
    // Get weather via wunderground api
    $json_url = 'http://api.wunderground.com/api/9252b3b729b18d24/conditions/astronomy/q/' . $o['ZipCode'] . '.json';
    $json_data = file_get_contents($json_url);
    $obj = json_decode($json_data, true);
    $windspeed = (int) $obj["current_observation"]['wind_mph'];
    $temperature = (int) $obj["current_observation"]['temp_f'];
    $wind_string = "";
    if ($windspeed == 0) {
        $wind_string = " Wind: Calm";
    } else {
        $wind_string = " Wind: " . $windspeed . " MPH " . $obj["current_observation"]['wind_dir'];
    }
    $weather_string = $obj["current_observation"]['weather'] . ' ' . $temperature . '°F' . ' -' . $wind_string;
    $weather_top = "Weather: " . $obj["current_observation"]['display_location']['full'];
    $geos[] = array('type' => 'plainText', 'font' => 'fontN', 'gravity' => 'center', 'text' => $weather_string, 'color' => 'white', 'x' => $boxX + $pad, 'y' => 1080 - $textBoxHeight - $bottom, 'w' => $boxWidth - $pad * 2, 'h' => $textBoxHeight);
    // Sub Title Bar
    $subTitleWidth = $o['subTitleWidth'];
    if ($subTitleWidth < 0) {
        $subTitleWidth = $boxWidth + $o['titleHeight'] + $o['subTitleWidth'];
    }
    $subTitleX = (1920 - $subTitleWidth) / 2;
    $geos[] = array('type' => 'slantRectangle', 'x' => $subTitleX + $pad, 'y' => 1080 - $boxHeight - $bottom + $o['titleHeight'], 'w' => $subTitleWidth, 'h' => $o['subTitleHeight'], 'color' => $o['subTitleColor']);
    // Title Bar
    $geos[] = array('type' => 'slantRectangle', 'x' => $boxX - $o['titleHeight'] / 2, 'y' => 1080 - $boxHeight - $bottom - 3, 'w' => $boxWidth + $o['titleHeight'], 'h' => $o['titleHeight'], 'color' => $o['titleColor']);
    $barTextPad = 3;
    if ($o['subTitleHeight'] > 0) {
        $geos[] = array('type' => 'shadowText', 'font' => 'fontN', 'gravity' => 'center', 'text' => $o['subTitleText'], 'color' => 'white', 'x' => $subTitleX + $o['subTitleHeight'] / 2, 'y' => 1080 - $boxHeight - $bottom + $o['titleHeight'] + $barTextPad, 'w' => $subTitleWidth - $o['subTitleHeight'], 'h' => $o['subTitleHeight'] - $barTextPad * 2);
    }
    $titleXAdjust = 0;
    $titleWAdjust = 0;
    $logoY = 1080 - $boxHeight - $bottom - ($logoHeight - $o['titleHeight']) / 2;
    // Left Logo
    //pull date from data stream for reliability else get server time
    //time in minutes
    if (isset($obj['moon_phase']['current_time'])) {
        $current_time = $obj['moon_phase']['current_time']['hour'] * 60 + $obj['moon_phase']['current_time']['minute'];
    } else {
        $current_time = date('H') * 60 + date('i');
    }
    //sunrise/sunset times
    //30 minutes adjustments account for when it is bright
    if (isset($obj['sun_phase'])) {
        $sunrise = $obj['sun_phase']['sunrise']['hour'] * 60 + $obj['sun_phase']['sunrise']['minute'] - 30;
        $sunset = $obj['sun_phase']['sunset']['hour'] * 60 + $obj['sun_phase']['sunset']['minute'] + 30;
    } else {
        $sunrise = 7 * 60 - 30;
        $sunset = 20 * 60 + 30;
    }
    //choose images based on available imageset
    $weather_images = array('Sunny' => 'clear.png', 'Clear' => 'clear.png', 'Scattered Clouds' => 'partly_cloudy.png', 'Partly Cloudy' => 'partly_cloudy.png', 'Mostly Cloudy' => 'partly_cloudy.png', 'Overcast' => 'cloudy.png', 'Cloudy' => 'cloudy.png', 'Light Rain' => 'rain.png', 'Heavy Rain' => 'rain.png', 'Rain' => 'rain.png', 'Rain Showers' => 'rain.png', 'Rain Mist' => 'rain.png', 'Drizzle' => 'rain.png', 'Hail' => 'hail.png', 'Hail Showers' => 'hail.png', 'Freezing Rain' => 'sleet.png', 'Freezing Drizzle' => 'sleet.png', 'Freezing Fog' => 'sleet.png', 'Snow' => 'snow.png', 'Snow Grains' => 'snow.png', 'Snow Showers' => 'snow.png', 'Thunder' => 'thunder_storms.png', 'Thunderstorm' => 'thunder_storms.png', 'Thunderstorms and Rain' => 'thunder_storms.png', 'Thunderstorms and Snow' => 'snow.png', 'Thunderstorms and Ice Pellets' => 'thunder_storms.png', 'Thunderstorms with Hail' => 'thunder_storms.png', 'Thunderstorms with Small Hail' => 'thunder_storms.png', 'Showers' => 'showers.png', 'Mist' => 'fog.png', 'Fog' => 'fog.png', 'Fog Patches' => 'fog.png', 'Shallow Fog' => 'fog.png', 'Partial Fog' => 'fog.png', 'Windy' => 'windy.png');
    //set weather image
    if (isset($weather_images[$obj['current_observation']['weather']])) {
        $use_img = true;
        $weather = $obj['current_observation']['weather'];
        $weather = str_replace('Heavy ', '', $weather);
        $weather = str_replace('Light ', '', $weather);
        //set weather image by time of day
        if ($current_time > $sunrise && $current_time < $sunset) {
            $sun_up = true;
        } else {
            $sun_up = false;
        }
        $file_path = 'other_graphics/weather/';
        $image_day_exists = file_exists($file_path . 'nt_' . $weather_images[$weather]);
        $image_night_exists = file_exists($file_path . $weather_images[$weather]);
        if ($sun_up && $image_day_exists) {
            $use_img = true;
            $img_location = $weather_images[$weather];
        } else {
            if (!$sun_up && ($image_night_exists || $image_day_exists)) {
                if ($image_night_exists) {
                    $use_img = true;
                    $img_location = 'nt_' . $weather_images[$weather];
                } else {
                    if ($image_day_exists) {
                        $use_img = true;
                        $img_location = $weather_images[$weather];
                    }
                }
            } else {
                $use_img = false;
            }
        }
    } else {
        $use_img = false;
    }
    if ($o['logoLeft'] && $logoHeight && $use_img) {
        $geos[] = array('type' => 'slantRectangle', 'color' => 'white', 'x' => $boxX - $logoHeight / 2, 'y' => $logoY, 'w' => $logoHeight * 2, 'h' => $logoHeight);
        $geos[] = array('type' => 'placeImage', 'path' => 'other_graphics/weather/' . $img_location, 'x' => $boxX, 'y' => $logoY, 'w' => $logoHeight, 'h' => $logoHeight);
        $titleXAdjust = $titleWAdjust = $logoXAdjust;
    }
    // Right Logo
    /*
    if ($o['logoRight'] && $logoHeight) {
    	$geos[] = array(
    			'type' => 'slantRectangle',
    			'color' => 'white',
    			'x' => $boxX + $boxWidth - $logoHeight*1.5,
    			'y' => $logoY,
    			'w' => $logoHeight*2,
    			'h' => $logoHeight
    	);
    	$geos[] = array(
    			'type' => 'placeImage',
    			'path' => $o['logoRight'],
    			'x' => $boxX + $boxWidth - $logoHeight,
    			'y' => $logoY,
    			'w' => $logoHeight,
    			'h' => $logoHeight,
    	);
    	$titleWAdjust += $logoXAdjust;
    }
    */
    $geos[] = array('type' => 'shadowText', 'font' => 'fontN', 'gravity' => "left", 'text' => $weather_top, 'color' => 'white', 'x' => $boxX + $titleXAdjust, 'y' => 1080 - $boxHeight - $bottom + $vbarTextPad, 'w' => $boxWidth - $titleWAdjust, 'h' => $o['titleHeight'] - $barTextPad * 2);
    foreach ($geos as $geo) {
        addGeoToCanvas($canvas, $geo, $bustCache);
    }
}
Ejemplo n.º 5
0
function gameSummary(&$canvas, $o)
{
    $maxHeight = 910;
    $width = 980;
    $height = $maxHeight;
    $plays = new Imagick();
    $plays->newPseudoImage($width, $height, 'xc:none');
    $teams = array();
    $teams['V'] = fetchTeam($o['vTeam']);
    $teams['H'] = fetchTeam($o['hTeam']);
    $bodyHeight = 200;
    $path = "http://www.sidearmstats.com/rpi/mhockey/1.xml";
    $path = "sidearm.xml";
    $path = $o['liveStatsXML'];
    $scores = getGameSummaryInfo($path);
    $vOffset = 0;
    $lastPeriod = 0;
    $playIndex = 0;
    foreach ($scores->score as $score) {
        $playIndex++;
        if ($vOffset + 150 > $maxHeight && $o["numPlays"] == "auto") {
            break;
        } else {
            if ($o["numPlays"] != "auto" && $o["numPlays"] + $o["startIndex"] < $playIndex) {
                break;
            }
        }
        if ($o["startIndex"] + 1 > $playIndex) {
            continue;
        }
        if ($vOffset > 0) {
            $plays->compositeImage(fillRectangle(960, 2, '#FFF'), imagick::COMPOSITE_OVER, 0, $vOffset);
        }
        if ($score['prd'] + 0 != $lastPeriod) {
            $lastPeriod = $score['prd'] + 0;
            $plays->compositeImage(periodLabel($lastPeriod), imagick::COMPOSITE_OVER, 0, $vOffset);
            $vOffset += 50;
            $plays->compositeImage(fillRectangle(960, 2, '#FFF'), imagick::COMPOSITE_OVER, 0, $vOffset);
        }
        $plays->compositeImage(scoringPlay($score, $teams), imagick::COMPOSITE_OVER, 0, $vOffset);
        $vOffset += 100;
        //print_r($score);
    }
    addGeoToCanvas($canvas, array('type' => 'flexBox', 'w' => 1920, 'h' => 1080, 'x' => 0, 'y' => 0, 'bodyText' => '', 'boxHeight' => $vOffset, 'boxWidth' => 1000, 'boxOffset' => 'auto', 'boxPadding' => 10, 'titleColor' => $o['barColor'], 'titleHeight' => '70', 'titleText' => $o['titleText'], 'titleGravity' => 'center', 'logoHeight' => 100, 'logoLeft' => $teams['H']['logo'], 'logoRight' => $teams['V']['logo']));
    $canvas->compositeImage($plays, imagick::COMPOSITE_OVER, (1920 - 980) / 2, 1080 - 50 - $vOffset - 10);
}