Convert sizes like 2em, 10cm or 12pt to pixels.

@param string $size The size string

@return int The pixel value
505184
public function getPixelValue(string $size)
    {
        $value = preg_replace('/[^0-9.-]+/', '', $size);
        $unit = preg_replace('/[^acehimnprtvwx%]/', '', $size);

        // Convert 16px = 1em = 2ex = 12pt = 1pc = 1/6in = 2.54/6cm = 25.4/6mm = 100%
        switch ($unit) {
            case '':
            case 'px':
                return (int) round($value);

                break;

            case 'em':
                return (int) round($value * 16);

                break;

            case 'ex':
                return (int) round($value * 16 / 2);

                break;

            case 'pt':
                return (int) round($value * 16 / 12);

                break;

            case 'pc':
                return (int) round($value * 16);

                break;

            case 'in':
                return (int) round($value * 16 * 6);

                break;

            case 'cm':
                return (int) round($value * 16 / (2.54 / 6));

                break;

            case 'mm':
                return (int) round($value * 16 / (25.4 / 6));

                break;

            case '%':
                return (int) round($value * 16 / 100);

                break;
        }

        return 0;
    }
1013021
public static function get_image_width($size)
    {
        // Get the size meta array.
        $size = static::get_image_size($size);

        if ($size === false) {
            return false;
        }

        if (isset($size['width'])) {
            return (int) $size['width'];
        }

        return false;
    }
609885
public function setSize($size = 32)
    {
        $size = (int)$size;

        // Gravatars can be sized 1px up to 2048px square: https://en.gravatar.com/site/implement/images/#size
        if ($size < 1) {
            $size = 1;
        }

        if ($size > 2048) {
            $size = 2048;
        }

        $this->size = $size;

        return $this;
    }
52042
public function formatFilesize($size)
        {
            $kb = 1024;
            $mb = 1048576;
            $gb = 1073741824;
            $tb = 1099511627776;

            if ($size < $kb) {
                return $size . " B";
            } else if ($size < $mb) {
                return round($size / $kb, 2) . " KB";
            } else if ($size < $gb) {
                return round($size / $mb, 2) . " MB";
            } else if ($size < $tb) {
                return round($size / $gb, 2) . " GB";
            } else {
                return round($size / $tb, 2) . " TB";
            }
        }
1350614
final static public function sizeTextToBytes (int $size=0, string $unit="") : int
	{
		$units = ['B' => 0, 'KB' => 1, 'MB' => 2, 'GB' => 3, 'TB' => 4, 'PB' => 5, 'EB' => 6, 'ZB' => 7, 'YB' => 8 ];
		return $size * pow(1024, $units[strtoupper($unit)]);
	}
32183
public function size( $size ) {
		$this->width  = (int) $size;
		$this->height = (int) $size;

		return $this;
	}
1100342
public function multiply(Size $size): Size
    {
        $this->bit = $this->bit * $size->get('b');
        return $this;
    }
1373668
public function setSize($size)
	{
		$this->size = $size;
		$this->pixelRatio = round($size / 5);

		return $this;
	}
77455
private function convertWithBytes($size)
    {
        $precision = 2;
        $base      = log($size, 1024);
        $suffixes  = array('B', 'KB', 'MB', 'GB', 'TB');
        $bytes     = round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)];

        return $bytes;
    }
664519
protected function convertToBytes($size)
	{
		if(is_numeric($unit = substr($size, -3)) === false)
		{
			$size = substr($size, 0, -3);

			switch($unit)
			{
				case 'KiB':
					return $size * 1024;
				case 'MiB':
					return $size * (1024 ** 2);
				case 'GiB':
					return $size * (1024 ** 3);
				case 'TiB':
					return $size * (1024 ** 4);
				case 'PiB':
					return $size * (1024 ** 5);
				case 'EiB':
					return $size * (1024 ** 6);
				case 'ZiB':
					return $size * (1024 ** 7);
				case 'YiB':
					return $size * (1024 ** 8);
				default:
					throw new RuntimeException(vsprintf('Invalid unit type [ %s ].', [$unit]));
			}
		}

		return (int) $size;
	}
1112330
public static function estimateBitsModeAn($size)
    {
        $w = (int)($size / 2);
        $bits = $w * 11;

        if($size & 1) {
            $bits += 6;
        }

        return $bits;
    }
339416
public static function byteConvert($size, $precision = 2)
    {

        // Sanity check
        if (!is_numeric($size)) {
            return '?';
        }

        // Get the notation
        $notation = self::$settings['byte_notation'] == 1000 ? 1000 : 1024;

        // Fixes large disk size overflow issue
        // Found at http://www.php.net/manual/en/function.disk-free-space.php#81207
        $types = array('B', 'KB', 'MB', 'GB', 'TB');
        $types_i = array('B', 'KiB', 'MiB', 'GiB', 'TiB');
        for ($i = 0; $size >= $notation && $i < (count($types) - 1); $size /= $notation, $i++);

        return(round($size, $precision).' '.($notation == 1000 ? $types[$i] : $types_i[$i]));
    }
301651
public static function getSize( $size )
    {
        $dim = [];
        if( is_array( $size ) )
        {
            $dim[ 'w' ] = $size[0];
            $dim[ 'h' ] = isset( $size[1] ) ? $size[1] : $size[0];
        }
        else
        {
            $dim[ 'w' ] = $size;
            $dim[ 'h' ] = null;
        }

        return $dim;
    }
1361987
protected function parseSize($size)
    {
        $result = null;
        $size = (string) $size;
        $matches = null;
        if (preg_match('/^\s*(\d+(?:\.\d*)?)\s*(?:([bkmgtpezy])b?)?\s*/i', $size, $matches)) {
            $value = (float) $matches[1];
            $unit = empty($matches[2]) ? 'b' : strtolower($matches[2]);
            if ($unit === 'b') {
                $result = (int) $value;
            } else {
                $result = (int) round($value * pow(1024, strpos('bkmgtpezy', $unit)));
            }
        }

        return $result;
    }
69697
public static function fileSize($size)
    {
        $units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB'];

        for ($i = 0; $size > 1024; $i++) {
            $size /= 1024;
        }

        return __('Size unit ' . $units[$i], round($size, 2));
    }
993147
public static function estimateBitsModeNum($size)
    {
        $w = (int)$size / 3;
        $bits = $w * 10;

        switch($size - $w * 3) {
            case 1:
                $bits += 4;
                break;
            case 2:
                $bits += 7;
                break;
            default:
                break;
        }

        return $bits;
    }
588441
private function normalize_int($size)
	{
		if (is_string($size)) {
			switch (substr($size, -1)) {
				case 'M': case 'm': return intval($size) * 1048576;
				case 'K': case 'k': return intval($size) * 1024;
				case 'G': case 'g': return intval($size) * 1073741824;
			}
		}

		return (int) $size;
	}