Creates the image buffer used by the skew functions.

@param int $size Size of the matrix.
@param int $ratio Rescale ratio of this image (value is returned by this method)
@return string Binary frame buffer
486310
protected function createImageMatrix($size = 0, &$ratio) {
		// create two-color image
		$this->toBinary(false);

		// rescale if necessary (for performance reasons)
		if($size > 0 && ($this->width > $size || $this->height > $size)) {
			if($this->width > $this->height) {
				$ratio = $size / $this->width;
			} else {
				$ratio = $size / $this->height;
			}
			$width = (int)($ratio * $this->width);
			$height = (int)($ratio * $this->height);
			$image = imagecreate($width, $height);
			imagecopyresized($image, $this->image, 0, 0, 0, 0, $width, $height, $this->width, $this->height);
		} else {
			$ratio = 1;
			$image = imagecreate($this->width, $this->height);
			imagecopy($image, $this->image, 0, 0, 0, 0, $this->width, $this->height);
			list($width, $height) = $this->getSize();
		}

		$this->image = $image;

		// find the background color (fast approximation)
		$bin = $this->getBinaryBuffer();
        $colors = count_chars($bin);

		arsort($colors, SORT_NUMERIC);
		reset($colors); // HipHop for PHP compatibility.
		$backgroundColor = key($colors);

		// make colors negation if necessary, 0's should be used for background.
		if($backgroundColor === 255) {
			imagefilter($this->image, IMG_FILTER_NEGATE);
		}

		$image = imagecreatetruecolor($size, $size);
		imagefill($image, 0, 0, 0);
		imagecopy($image, $this->image, ($size - $width) / 2, ($size - $height) / 2, 0, 0, $width, $height);
		$this->image = $image;

		$bin = $this->getBinaryBuffer();

		$this->getSize();
		return $bin;
	}
1203018
public function resize($destination, $width, $height, $cropX=0, $cropY=0, $ratio=null)
    {
        if ($ratio) {
            $this->ratio = $ratio;
        }

        $size = $this->defineSize($width, $height);

        return $this->doResize($destination, $size, $cropX, $cropY, false);
    }
681092
public static function formatByteSize( $size, $precision = 1, $symbols = NULL )
    {
        if ( $symbols === NULL ){
            $symbols = array('B', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb');
        }
        $i=0;
        while (($size/1024)>1) {
            $size=$size/1024;
            $i++;
        }
        return (round($size,$precision)." ".$symbols[$i]);
    }
1032086
protected function readLine($size = 1024)
    {
        $line = '';

        if (!$size) {
            $size = 1024;
        }

        do {
            if ($this->eof()) {
                return $line ?: null;
            }

            $buffer = fgets($this->fp, $size);

            if ($buffer === false) {
                $this->closeSocket();
                break;
            }

            if ($this->debug) {
                $this->debug('S: '. rtrim($buffer));
            }

            $line .= $buffer;
        }
        while (substr($buffer, -1) != "\n");

        return $line;
    }
1153867
public function readableSize($size, $decimals = 0, $binarySuffix = false)
    {
        $formatter = new FilesizeFormatter();

        return $formatter->formatFilesize($size, $decimals, $binarySuffix);
    }
1025250
public function median(int $size): Image
    {
        return $this->rank($size, $size, ($size * $size) / 2);
    }
545818
public function divide(Size $size): Size
    {
        if (0 === $size->get('b')) {
            throw new \OutOfBoundsException('Could not divide by zero.');
        }

        $this->bit = \ceil($this->bit / $size->get('b'));

        return $this;
    }
118776
public function scale($ratio)
    {
        $_width = (int)$this->do_getWidth();
        $_height = (int)$this->do_getHeight();

        if ($ratio === 1) {
            return $this;
        }

        $width = (int)($_width * $ratio);
        $height = (int)($_height * $ratio);

        $this->do_resize($width, $height);

        return $this;
    }
422258
public function buildAvatar($size = 150)
    {
        $gravatar = new Gravatar();
        $gravatar->setAvatarSize($size);
        $gravatar->enableSecureImages();

        return $gravatar->buildGravatarURL($this->getUserEmail());
    }
819867
public function appendBytes($size, $data)
    {
        if ($size == 0)
            return 0;

        $b = QRbitstream::newFromBytes($size, $data);

        if(is_null($b))
            return -1;

        $ret = $this->append($b);
        unset($b);

        return $ret;
    }
969356
private function setImageSize($image, $size, $needExactSize = false)
    {
        if (empty($size)) {
            return $image;
        }

        if ($needExactSize || $image->getImageWidth() > $size[0]) {
            if ($size[0] == 0 || $size[1] == 0) {
                $image->scaleImage($size[0], $size[1]);
            } else {
                $image->cropThumbnailImage($size[0], $size[1]);
            }
        }

        return $image;
    }
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();
	}
925497
public function generate($size)
    {
        if (!$this->hasLibsodium || $size < 1) {
            return str_repeat(chr(0), $size);
        }

        return \Sodium\randombytes_buf($size);
    }
118168
public static function getImageSize( string $size = 'thumbnail') {
		$sizes = self::getImageSizes();
		$size  = key_exists( $size, $sizes ) ? $size : 'thumbnail';

		return $sizes[ $size ];
	}
1324806
public static function filesizeToBytes($size)
    {
        $unit = preg_replace('/[^bkmgtpezy]/i', '', $size);
        $size = preg_replace('/[^0-9\.]/', '', $size);

        if ($unit) {
            return round($size * pow(1024, stripos('bkmgtpezy', $unit[0])));
        }

        return round($size);
    }
276660
public function getPortraitFile($size)
    {
        if (strpos($this->filename, '/')) {
            $filename = str_replace('/', '/avatars/'.$size, $this->filename);
        } else {
            $filename = $this->component.'/avatars/'.$size.$this->filename;
        }

        return $filename;
    }
709722
public function fit(Size $size, $position = 'center')
    {
        // create size with auto height
        $auto_height = clone $size;

        $auto_height->resize($this->width, null, function ($constraint) {
            $constraint->aspectRatio();
        });

        // decide which version to use
        if ($auto_height->fitsInto($this)) {

            $size = $auto_height;

        } else {

            // create size with auto width
            $auto_width = clone $size;

            $auto_width->resize(null, $this->height, function ($constraint) {
                $constraint->aspectRatio();
            });

            $size = $auto_width;
        }

        $this->align($position);
        $size->align($position);
        $size->setPivot($this->relativePosition($size));

        return $size;
    }