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); }
function slantRectangle(&$canvas, $o) { $background = "#FFFFFF"; //$ltr = '#000000'; $ltr = '#888'; $bd = '#A6A6A6'; $iglow = '#404040'; try { $gradient1 = new Imagick(); $gradient1->newPseudoImage($o['h'], $o['w'] * 3 / 8, "gradient:white-$ltr"); $gradient1->rotateImage(new ImagickPixel(), 270); $gradient2 = new Imagick(); $gradient2->newPseudoImage($o['h'], $o['w'] * 3 / 8, "gradient:$ltr-white"); $gradient2->rotateImage(new ImagickPixel(), 270); $lefttoright = new Imagick(); $lefttoright->newPseudoImage($o['w'], $o['h'], "xc:$ltr"); $lefttoright->compositeImage($gradient1, imagick::COMPOSITE_OVER, 0, 0); $lefttoright->compositeImage($gradient2, imagick::COMPOSITE_OVER, $o['w'] * 5 / 8, 0); $whiteup = new Imagick(); $whiteup->newPseudoImage($o['w'], $o['h'] / 2, "gradient:black-#888"); $gradient1 = new Imagick(); $gradient1->newPseudoImage($o['w'], $o['h'] / 7, "gradient:$bd-white"); $gradient2 = new Imagick(); $gradient2->newPseudoImage($o['w'], $o['h'] / 7, "gradient:white-$bd"); $bottomdark = new Imagick(); $bottomdark->newPseudoImage($o['w'], $o['h'], "xc:white"); $bottomdark->compositeImage($gradient1, imagick::COMPOSITE_OVER, 0, 0); $bottomdark->compositeImage($gradient2, imagick::COMPOSITE_OVER, 0, ($o['h'] / 2) - ($o['h'] / 7)); $background = fillRectangle($o['w'], $o['h'], $o['color']); $background->compositeImage($lefttoright, imagick::COMPOSITE_MULTIPLY, 0, 0); // experimental if ($o['image']) { $logo = new Imagick(); $logo->readImage(realpath($o['image'])); $logo->resizeImage($o['h'], $o['h'], imagick::FILTER_TRIANGLE, 1); $background->compositeImage($logo, imagick::COMPOSITE_OVER, $o['w'] - $o['h'] - ($o['h'] / 3), 0); } $background->compositeImage($whiteup, imagick::COMPOSITE_SCREEN, 0, 0); $background->compositeImage($bottomdark, imagick::COMPOSITE_MULTIPLY, 0, $o['h'] / 2); $slantleft = new Imagick(); $slantleft->newPseudoImage($o['h'] * sqrt(5) / 2, 8, "gradient:$iglow-white"); $slantleft->rotateImage("none", 296.6); $slantright = new Imagick(); $slantright->newPseudoImage($o['h'] * sqrt(5) / 2, 8, "gradient:$iglow-white"); $slantright->rotateImage("none", 117.2); $top = new Imagick(); $top->newPseudoImage($o['w'], 8, "gradient:$iglow-white"); $bottom = new Imagick(); $bottom->newPseudoImage($o['w'], 8, "gradient:white-$iglow"); $slants = new Imagick(); $slants->newPseudoImage($o['w'], $o['h'], "xc:white"); $slants->compositeImage($slantleft, imagick::COMPOSITE_OVER, -1, 0); $slants->compositeImage($slantright, imagick::COMPOSITE_OVER, $o['w'] - ($o['h'] / 2) - 9, 0); $slants->compositeImage($top, imagick::COMPOSITE_MULTIPLY, 0, 0); $slants->compositeImage($bottom, imagick::COMPOSITE_MULTIPLY, 0, $o['h'] - 8); $background->compositeImage($slants, imagick::COMPOSITE_MULTIPLY, 0, 00); $draw1 = new ImagickDraw(); $draw1->pushPattern('gradient', 0, 0, $o['w'], $o['h']); $draw1->composite(Imagick::COMPOSITE_OVER, 0, 0, $o['w'], $o['h'], $background); $draw1->popPattern(); $draw1->setFillPatternURL('#gradient'); $draw1->polygon(array(array('x' => 00, 'y' => $o['h'] - 1), array('x' => ($o['h'] / 2) - 1, 'y' => 00), array('x' => $o['w'] - 1, 'y' => 00), array('x' => $o['w'] - ($o['h'] / 2) - 1, 'y' => $o['h'] - 1))); $points = array(array('x' => 0, 'y' => $o['h'] - 1), array('x' => ($o['h'] / 2) - 1, 'y' => 00), array('x' => $o['w'] - 1, 'y' => 00), array('x' => $o['w'] - ($o['h'] / 2) - 1, 'y' => $o['h'] - 1)); for ($i = 0; $i < 4; $i++) { $points[$i]['x']+=10; $points[$i]['y']+=10; } $shadow = new Imagick(); $shadow->newPseudoImage($o['w'] + 20, $o['h'] + 20, "xc:none"); $draws = new ImagickDraw(); $draws->setFillColor("black"); $draws->polygon($points); $shadow->drawImage($draws); $shadow->blurImage(0, 4, imagick::CHANNEL_ALPHA); $im = new Imagick(); $im->newPseudoImage($o['w'], $o['h'], "xc:none"); $im->drawImage($draw1); $im2 = new Imagick(); $im2->newPseudoImage($o['w'] + 50, $o['h'] + 50, "xc:none"); $im2->compositeImage($shadow, imagick::COMPOSITE_OVER, 5, 5); $draw1 = new ImagickDraw(); $draw1->setStrokeWidth(6); $draw1->setStrokeColor("black"); $draw1->polygon($points); $draw1->setStrokeWidth(2); $draw1->setStrokeColor("white"); $draw1->polygon($points); $im2->drawImage($draw1); $im2->compositeImage($im, imagick::COMPOSITE_OVER, 10, 10); $canvas->compositeImage($im2, imagick::COMPOSITE_OVER, $o['x'] - 10, $o['y'] - 10); } catch (Exception $e) { echo 'Error: ', $e->getMessage(), ""; } }
} </style> <pre> <? $includePath = '../'; include($includePath . 'include.php'); $w = $h = 200; $gradients = ['linear-gradient(red,white)', 'linear-gradient(to right, red, white)', 'linear-gradient(to right, #FF0000, rgb(255,255,255))', 'linear-gradient(to right, red, black 50%, white)', 'linear-gradient(to right, red 10%, black 50%, white)', 'linear-gradient(to right, red 10%, black 50%, white 90%)']; foreach($gradients as $gradient) { echo '<p>' . $gradient . '</p>'; echo '<div style="background:' . $gradient . ';width:'.$w.'px;height:'.$h.'px;">CSS</div>'; $canvas = new Imagick(); $canvas->newImage($w, $h, "none", 'png'); $canvas->setImageDepth(8); $canvas->setimagecolorspace(imagick::COLORSPACE_SRGB); $result = fillRectangle($w,$h,$gradient); $canvas->compositeImage($result,Imagick::COMPOSITE_OVER,0,0); echo '<div style="background:url(data:image/gif;base64,' . base64_encode($canvas) . ');width:'.$w.'px;height:'.$h.'px;">Imagick</div>'; }