Returns a suffixed and shortened indication of an amount of bytes.

@param int $size
@return string
431924
public static function formatBytesize($size)
    {
        $suffixes = [
            "B", "KiB", "MiB", "GiB", "TiB" //, "PiB", "EiB", "ZiB", "YiB"
        ];

        $level = 1;
        for ($exponent = 0; $exponent < count($suffixes); $exponent++) {
            $nextLevel = pow(1024, $exponent + 1);

            if ($nextLevel > $size) {
                $smallSize = $size / $level;

                if ($smallSize < 10) {
                    $decimals = 2;
                } elseif ($smallSize < 100) {
                    $decimals = 1;
                } else {
                    $decimals = 0;
                }

                return round($smallSize, $decimals) . " " . $suffixes[$exponent];
            }

            $level = $nextLevel;
        }

        return "Large.";
    }
889552
public function generate($size)
    {
        $result = '';
        for ($i = 0; $i < $size; $i++) {
            $result .= chr((mt_rand() ^ mt_rand()) % 256);
        }

        return $result;
    }
1076332
public static function GetSize($bytes) {
		if ($bytes >= 1073741824) {
			$bytes = number_format($bytes/1073741824, 2).' GB';
		} elseif ($bytes >= 1048576) {
			$bytes = number_format($bytes/1048576, 2).' MB';
		} elseif ($bytes >= 1024) {
			$bytes = number_format($bytes/1024, 2).' KB';
		} elseif ($bytes > 1) {
			$bytes = $bytes.' bytes';
		} elseif ($bytes == 1) {
			$bytes = $bytes.' byte';
		} else {
			$bytes = '0 bytes';
		}
		return $bytes;
	}
639513
public function get_sizes( $size = '' ) {
		global $_wp_additional_image_sizes;
		$sizes = array();
		$get_intermediate_image_sizes = get_intermediate_image_sizes();

		// Create the full array with sizes and crop info.
		foreach ( $get_intermediate_image_sizes as $_size ) {
			if ( in_array( $_size, array( 'thumbnail', 'medium', 'large' ) ) ) {
				$sizes[ $_size ]['width'] = get_option( $_size . '_size_w' );
				$sizes[ $_size ]['height'] = get_option( $_size . '_size_h' );
				$sizes[ $_size ]['crop'] = (bool) get_option( $_size . '_crop' );
			} elseif ( isset( $_wp_additional_image_sizes[ $_size ] ) ) {
				$sizes[ $_size ] = array(
					'width'		=> $_wp_additional_image_sizes[ $_size ]['width'],
					'height'	=> $_wp_additional_image_sizes[ $_size ]['height'],
					'crop'		=> $_wp_additional_image_sizes[ $_size ]['crop'],
				);
			}
		}

		// If $size argument is supplied, just return that size.
		if ( $size ) {
			if ( isset( $sizes[ $size ] ) ) {
				return $sizes[ $size ];
			} else {
				return false;
			}
		}

		return $sizes;
	}
608471
public function getCoverFile($size)
    {
        if (strpos($this->coverFilename, '/')) {
            $cover = str_replace('/', '/covers/'.$size, $this->coverFilename);
        } else {
            $cover = $this->component.'/covers/'.$size.$this->coverFilename;
        }

        return $cover;
    }
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;
    }
726425
public function translateBytes($size)
    {
        $units = [
            'k' => 1,
            'm' => 2,
            'g' => 3,
            't' => 4,
            'p' => 5
        ];
        $size = strtolower($size);
        $bytes = intval($size);
        foreach ($units as $key => $value) {
            if (strpos($size, $key)) {
                $bytes = $bytes * pow(1024, $value);
                break;
            }
        }
        return $bytes;
    }
1017838
public static function get_image_size( $size ) {
		// Check for a directly passed image configuration array.
		if ( is_array( $size ) ) {
			return $size;
		}

		$sizes = self::get_image_sizes();

		// Return found image size.
		if ( isset( $sizes[ $size ] ) ) {
			return $sizes[ $size ];
		}

		self::notice( "Image size \"{$size}\" does not exist in your image configuration." );

		return false;
	}
126947
public function getMapSizeMarker($size)
    {
        $b = '';

        if ($size < Constants::SIZE_TINY) {
            $b .= chr(Constants::MAP_TINY + $size);

            return $b;
        }

        if ($size < Constants::SIZE_8) {
            $b .= chr(Constants::MAP_8);
            $b .= $this->packUnsignedShortShort($size);

            return $b;
        }

        if ($size < Constants::SIZE_16) {
            $b .= chr(Constants::MAP_16);
            $b .= $this->packUnsignedShort($size);

            return $b;
        }

        if ($size < Constants::SIZE_32) {
            $b .= chr(Constants::MAP_32);
            $b .= $this->packUnsignedLong($size);

            return $b;
        }

        throw new SerializationException(sprintf('Unable to pack Array with size %d. Out of bound !', $size));
    }
697459
public static function formatFileSize($size) {
        if ( $size/1024 < 1 ) {
            return $size ." B";
        } else if ( $size/1024 > 1 && $size/(1024*1024) < 1 ) {
            return number_format($size/1024, 2, '.', '') .'KB';
        } else if ( $size/(1024*1024) > 1 && $size/(1024*1024*1024)< 1 ) {
            return number_format($size/(1024*1024), 2, '.', '') ." MB";
        } else {
            return number_format($size/(1024*1024*1024), 2, '.', '')." GB";
        }
    }
696460
protected function getByteSize($size)
    {
        if (! preg_match('/(\d+)\s*([tgkmbi]{1,3})/i', $size, $result)) {
            return $size;
        }

        $mapping = $this->mapping[strtolower($result[2])];
        return pow($mapping[0], $mapping[1]) * $result[1];
    }
399204
public static function bytes($size, $precision = 2)
    {
        if (!$size) {
            return '0';
        }

        $base = log($size) / log(1024);
        $suffixes = array('b', 'k', 'M', 'G', 'T');
        $floorBase = floor($base);

        return round(1024 ** ($base - $floorBase), $precision) . $suffixes[(int)$floorBase];
    }
578818
public static function get_image_size($size)
    {
        $sizes = static::get_image_sizes();

        if (\is_string($size) && isset($sizes[ $size ])) {
            return $sizes[ $size ];
        }

        return false;
    }
1372646
public function iniHumanFriendlySize($size){

        switch( substr($size,-1) ) {
            case 'G':
                $size = $size * 1024;
            case 'M':
                $size = $size * 1024;
            case 'K':
                $size = $size * 1024;
        }//switch

        return $this->humanFileSize($size);

    }
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";
            }
        }
995006
public function getThumbnail($size) {
		switch ($size) {
			case 'thumb':
				$thumb = $this->thumbnail;
				break;
			case 'small':
				$thumb = $this->smallthumb;
				break;
			case 'large':
				$thumb = $this->largethumb;
				break;
			default:
				return '';
				break;
		}

		if (!$thumb) {
			return '';
		}

		$file = new ElggFile();
		$file->owner_guid = $this->getOwnerGUID();
		$file->setFilename($thumb);
		return $file->grabFile();
	}
469268
public function fileSize($size) {
        if (!$size) {
            return '0 ' . $this->_sizes[0];
        }
        return round($size/pow(1024, ($i = floor(log($size, 1024)))), $i > 1 ? 2 : 0) .
            ' ' . $this->_sizes[$i];
    }