Skip to content

Instantly share code, notes, and snippets.

@matthisamoto
Last active August 29, 2015 14:07
Show Gist options
  • Save matthisamoto/ea4f0cfff230afc87cd2 to your computer and use it in GitHub Desktop.
Save matthisamoto/ea4f0cfff230afc87cd2 to your computer and use it in GitHub Desktop.
Draw SVG Arrows with PHP
function drawSVGArrow($width, $height, $direction = "right") {
switch ($direction) {
case "right":
$points = array(
"0, 0",
$width.", ".floor($width/2),
"0, ".$width
);
$ie = '▶';
break;
case "left":
$points = array(
$width.", 0",
"0, ".floor($width/2),
$width.", ".$width
);
$ie = '◀';
break;
case "down":
$points = array(
"0, 0",
$width.", 0",
floor($width/2).", ".$width
);
$ie = '▼';
break;
case "up":
$points = array(
floor($width/2).", 0",
$width.", ".$width,
"0, ".$width
);
$ie = '▲';
}
$svg = '<svg width="'.$width.'" height="'.$height.'" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">';
$svg .= '<polygon points="'.join($points, " ").'"/>';
$svg .= '</svg>';
$html = '<!--[if lte IE 8]>';
$html .= '<span class="arrow_icon" style="font-size:'.floor(1.6666667 * $height).'px;font-family:Lucida Sans Unicode,Arial Unicode MS,sans-serif;">'.$ie.'</span>';
$html .= '<![endif]-->';
$html .= '<!--[gt IE 8]>';
$html .= $svg;
$html .= '<![endif]-->';
$html .= '<!--[if !IE]><!-->';
$html .= $svg;
$html .= '<!--<![endif]-->';
return $html;
}
drawSVGArrow(12, 12, "right");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment