Skip to content

Commit

Permalink
Make the mapper array a class property.
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Oct 17, 2017
1 parent 716a2e4 commit d8dd309
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ class Image extends AbstractImage
*/
private $palette;

/**
* @var array
*/
private static $map = [
'px' => 1,
'em' => 16,
'ex' => 16 / 2,
'pt' => 16 / 12,
'pc' => 16,
'in' => 16 * 6,
'cm' => 16 / (2.54 / 6),
'mm' => 16 / (25.4 / 6),
];

/**
* @param \DOMDocument $document
* @param MetadataBag $metadata
Expand Down Expand Up @@ -455,24 +469,13 @@ private function fixViewBox()
*/
private function getPixelValue($size)
{
$map = [
'px' => 1,
'em' => 16,
'ex' => 16 / 2,
'pt' => 16 / 12,
'pc' => 16,
'in' => 16 * 6,
'cm' => 16 / (2.54 / 6),
'mm' => 16 / (25.4 / 6),
];

$size = trim($size);

$value = substr($size, 0, -2);
$unit = substr($size, -2);

if (isset($map[$unit]) && is_numeric($value)) {
$size = $value * $map[$unit];
if (isset($this->map[$unit]) && is_numeric($value)) {
$size = $value * $this->map[$unit];
}

if (is_numeric($size)) {
Expand Down

0 comments on commit d8dd309

Please sign in to comment.