Esempio n. 1
0
 /**
  * Places a text on top of the current image, for writing text using relative positioning. To
  * overwrite the current Drawer settings, create a custom Drawer object and use the setDrawer()
  * method before.
  *
  * @param string $text           Text to be written.
  * @param int    $place_constant One of the Imanee:IM_POS constants.
  * @param int    $fitWidth       If a positive value is provided, will change the font size to
  *                               fit the text in this width.
  * @param int $fontSize          The font size. Defaults to the current font size defined in the
  *                               Drawer.
  *
  * @return $this
  *
  * @throws UnsupportedMethodException
  */
 public function placeText($text, $place_constant = Imanee::IM_POS_TOP_LEFT, $fitWidth = 0, $fontSize = 0)
 {
     if (!$this->resource instanceof ImageWritableInterface) {
         throw new UnsupportedMethodException("This method is not supported by the ImageResource in use.");
     }
     if ($fontSize) {
         $this->getDrawer()->setFontSize($fontSize);
     }
     if ($fitWidth > 0) {
         $this->setDrawer($this->adjustFontSize($text, $this->getDrawer(), $fitWidth));
     }
     list($coordX, $coordY) = PixelMath::getPlacementCoordinates($this->resource->getTextGeometry($text, $this->getDrawer()), $this->getSize(), $place_constant);
     $this->resource->annotate($text, $coordX, $coordY + $this->resource->getFontSize($this->getDrawer()), 0, $this->getDrawer());
     return $this;
 }