Pop\Image\Svg::text PHP Метод

text() публичный Метод

Create text within the an SVG image object.
public text ( string $str, integer | string $size, integer | string $x, integer | string $y, string $font = 'Arial', integer | string $rotate = null, boolean $bold = false ) : Svg
$str string
$size integer | string
$x integer | string
$y integer | string
$font string
$rotate integer | string
$bold boolean
Результат Svg
    public function text($str, $size, $x, $y, $font = 'Arial', $rotate = null, $bold = false)
    {
        $text = $this->resource->addChild('text', $str);
        $text->addAttribute('x', $x . $this->units);
        $text->addAttribute('y', $y . $this->units);
        $text->addAttribute('font-size', $size);
        $text->addAttribute('font-family', $font);
        if (null !== $this->fillColor) {
            $text->addAttribute('fill', $this->fillColor->get(3, true));
            if ($this->opacity < 1.0) {
                $text->addAttribute('fill-opacity', $this->opacity);
            }
        }
        if (null !== $rotate) {
            $text->addAttribute('transform', 'rotate(' . $rotate . ' ' . $x . ',' . $y . ')');
        }
        if ($bold) {
            $text->addAttribute('font-weight', 'bold');
        }
        return $this;
    }

Usage Example

Пример #1
0
 public function testText()
 {
     $s = new Svg('graph.svg', '640px', '480px');
     $s->setFillColor(new Rgb(255, 0, 0));
     $s->text('Hello World', 36, 10, 100, 'Arial', 10, true);
     $this->assertEquals(640, $s->getWidth());
 }