Last active
December 17, 2015 04:19
-
-
Save microweber/5549593 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function svgScaleHack($svg, $minWidth, $minHeight) | |
{ | |
$reW = '/(.*<svg[^>]* width=")([\d.]+px)(.*)/si'; | |
$reH = '/(.*<svg[^>]* height=")([\d.]+px)(.*)/si'; | |
preg_match($reW, $svg, $mw); | |
preg_match($reH, $svg, $mh); | |
if(!isset($mw[2]) and isset($mh[2])){ | |
$mw[2] = $mh[2]; | |
} | |
if(empty($mw)){ | |
$width = floatval($minWidth); | |
$height = floatval($minHeight); | |
} else { | |
$width = floatval($mw[2]); | |
$height = floatval($mh[2]); | |
} | |
if (!$width || !$height) return false; | |
// scale to make width and height big enough | |
$scale = 1; | |
if ($width < $minWidth){ | |
$scale = $minWidth/$width; | |
} | |
if ($height < $minHeight){ | |
$scale = max($scale, ($minHeight/$height)); | |
} | |
$scale = 1; | |
//$width *= $scale*2; | |
//$height *= $scale*2; | |
$svg = preg_replace($reW, "\${1}{$width}px\${3}", $svg); | |
$svg = preg_replace($reH, "\${1}{$height}px\${3}", $svg); | |
return $svg; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment