/** * Constructor. * @param string $text * @throws Exceptions\ExtensionException * @throws \BadMethodCallException * @throws Exceptions\FileException */ public function __construct($text = '') { if (extension_loaded('gd') === FALSE) { throw new Exceptions\ExtensionException('PHP extension GD is not loaded.'); } if (is_string($text) === FALSE) { throw new \BadMethodCallException('Parameter "text" must be string.'); } $this->text = $text; $this->fontPath = __DIR__ . '/../fonts/open-sans/OpenSans-Regular.ttf'; if (is_readable($this->fontPath) === FALSE) { throw new Exceptions\FileException('Directory with fonts "' . $this->fontPath . '" does not exist or is not readable.'); } $this->setBackgroundColor(Objects\Color::create('white')); $this->setTextColor(Objects\Color::create('black')); $this->setBorderColor(Objects\Color::create('grey')); }
/** * Add text to GD image. * @param resource $image * @param string $text * @param string $font * @param int $fontSize * @param Objects\Color $textColor * @param array $offset * @return resource */ private static function addTextToImage($image, $text, $font, $fontSize, Objects\Color $textColor, array $offset) { $color = Objects\Color::allocateToImage($image, $textColor); imagettftext($image, $fontSize, 0, $offset[TextImage::OPT_LEFT], $offset[TextImage::OPT_TOP], $color, $font, $text); return $image; }