Grafika\Grafika::fontsDir PHP Method

fontsDir() public static method

Return path to directory containing fonts used in text operations.
public static fontsDir ( ) : string
return string
    public static function fontsDir()
    {
        $ds = DIRECTORY_SEPARATOR;
        return realpath(self::DIR . $ds . '..' . $ds . '..') . $ds . 'fonts';
    }

Usage Example

Beispiel #1
0
 /**
  * Write text to image.
  *
  * @param Image $image
  * @param string $text The text to be written.
  * @param int $size The font size. Defaults to 12.
  * @param int $x The distance from the left edge of the image to the left of the text. Defaults to 0.
  * @param int $y The distance from the top edge of the image to the top of the text. Defaults to 12 (equal to font size) so that the text is placed within the image.
  * @param Color $color The Color object. Default text color is black.
  * @param string $font Full path to font file. If blank, will default to Liberation Sans font.
  * @param int $angle Angle of text from 0 - 359. Defaults to 0.
  *
  * @return EditorInterface
  * @throws \Exception
  */
 public function text(&$image, $text, $size = 12, $x = 0, $y = 0, $color = null, $font = '', $angle = 0)
 {
     if ($image->isAnimated()) {
         // Ignore animated GIF for now
         return $this;
     }
     $y += $size;
     $color = $color !== null ? $color : new Color('#000000');
     $font = $font !== '' ? $font : Grafika::fontsDir() . DIRECTORY_SEPARATOR . 'LiberationSans-Regular.ttf';
     list($r, $g, $b, $alpha) = $color->getRgba();
     // Set up draw properties
     $draw = new \ImagickDraw();
     // Text color
     $draw->setFillColor(new \ImagickPixel("rgba({$r}, {$g}, {$b}, {$alpha})"));
     // Font properties
     $draw->setFont($font);
     $draw->setFontSize($size);
     // Write text
     $image->getCore()->annotateImage($draw, $x, $y, $angle, $text);
     return $this;
 }
All Usage Examples Of Grafika\Grafika::fontsDir