Skip to content

Instantly share code, notes, and snippets.

@ahebrank
Created September 3, 2014 13:17
Show Gist options
  • Save ahebrank/150f4b410e89db4e77d4 to your computer and use it in GitHub Desktop.
Save ahebrank/150f4b410e89db4e77d4 to your computer and use it in GitHub Desktop.
Make some stripes (because linear gradients just don't work)
<?php
// make an svg given an initial stripe color, initial stripe height, other stripe height, and total overall height
$osh = $_GET['oh']; // stripe height
$h = $_GET['h']; // overall height
$isc = (isset($_GET['c']))? $_GET['c']:""; // optional initial stripe
$ish = (isset($_GET['ch']))? $_GET['ch']:0; // height of initial stripe
$offset = (isset($_GET['offset']))? $_GET['offset']:0; // "offset" (actually just the height of the first stripe)
$altcolors = array("#ededeb", "#e4e4e3");
// you'll need to repeat me horizontally
$w = 5;
// initialize the svg
$svg = '<svg width="'.$w.'" height="'.$h.'" xmlns="http://www.w3.org/2000/svg">'.
' <g><title>stripe bg</title>';
// track the number of stripes and the total height
$c = 0;
$th = 0;
if ($offset) {
$svg .= ' <rect id="svg_'.$c.'" height="'.$offset.'" width="'.$w.'" y="'.$th.'" x="0" fill="'.$altcolors[0].'" />';
$th += $offset;
}
// the colored stripe
if ($ish > 0) {
$c += 1;
$svg .= ' <rect id="svg_'.$c.'" height="'.$ish.'" width="'.$w.'" y="'.$th.'" x="0" fill="#'.$isc.'" />';
$th += $ish;
}
while ($th < $h) {
$c += 1;
$fill = $altcolors[($c % count($altcolors))];
$svg .= ' <rect id="svg_'.$c.'" height="'.$osh.'" width="'.$w.'" y="'.$th.'" x="0" fill="'.$fill.'" />';
$th += $osh;
}
// close out the svg
$svg .= '</g></svg>';
header("Content-type: image/svg+xml");
echo $svg;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment