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;
	}