PHPePub\Helpers\ImageHelper::scaleSVGUnit PHP Method

scaleSVGUnit() public static method

Copyright WikiMedia: https://doc.wikimedia.org/mediawiki-core/master/php/SVGMetadataExtractor_8php_source.html
public static scaleSVGUnit ( $length, integer $portSize = 512 ) : float
$length
$portSize integer
return float
    public static function scaleSVGUnit($length, $portSize = 512)
    {
        static $unitLength = array('px' => 1.0, 'pt' => 1.25, 'pc' => 15.0, 'mm' => 3.543307, 'cm' => 35.43307, 'in' => 90.0, 'em' => 16.0, 'ex' => 12.0, '' => 1.0);
        $matches = array();
        if (preg_match('/^\\s*(\\d+(?:\\.\\d+)?)(em|ex|px|pt|pc|cm|mm|in|%|)\\s*$/', $length, $matches)) {
            $length = floatval($matches[1]);
            $unit = $matches[2];
            if ($unit == '%') {
                return $length * 0.01 * $portSize;
            } else {
                return $length * $unitLength[$unit];
            }
        } else {
            // Assume pixels
            return floatval($length);
        }
    }