コード例 #1
0
ファイル: Image.php プロジェクト: codeforamerica/oakland-beta
 /**
  * Get the bounding text box for a text string and an angle
  *
  * @param $text
  * @param int $angle
  *
  * @throws Exception
  * @return \Imagine\Image\BoxInterface
  */
 public function getTextBox($text, $angle = 0)
 {
     if (empty($this->_font)) {
         throw new Exception(Craft::t("No font properties have been set. Call Image::setFontProperties() first."));
     }
     return $this->_font->box($text, $angle);
 }
コード例 #2
0
ファイル: ImageHelper.php プロジェクト: ambient-lounge/site
 /**
  * Calculates size for bounding box of string written in given font.
  *
  * @param string        $string
  * @param FontInterface $font
  *
  * @return bool|Box Instance of Box object, false on error
  */
 public static function calculateTextSize($string, FontInterface $font)
 {
     $imagine = Tygh::$app['image'];
     if ($imagine instanceof \Imagine\Imagick\Imagine && class_exists('ImagickDraw')) {
         $text = new \ImagickDraw();
         $text->setFont($font->getFile());
         if (version_compare(phpversion("imagick"), "3.0.2", ">=")) {
             $text->setResolution(96, 96);
             $text->setFontSize($font->getSize());
         } else {
             $text->setFontSize((int) ($font->getSize() * (96 / 72)));
         }
         $imagick = new \Imagick();
         $info = $imagick->queryFontMetrics($text, $string);
         $text->clear();
         $text->destroy();
         $imagick->clear();
         $imagick->destroy();
         return new Box($info['textWidth'], $info['textHeight']);
     }
     if ($imagine instanceof \Imagine\Gd\Imagine && function_exists('imagettfbbox')) {
         $ttfbbox = imagettfbbox($font->getSize(), 0, $font->getFile(), $string);
         return new Box(abs($ttfbbox[2]), abs($ttfbbox[7]));
     }
     return false;
 }
コード例 #3
0
ファイル: GraphicsContext.php プロジェクト: appotter/phppdf
 private function getWidthOfSpaceChar(ImagineFont $font)
 {
     return $font->box(' ')->getWidth();
 }