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

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

Create text within the an image object
public text ( string $str, integer | string $size, integer | string $x, integer | string $y, string $font = null, integer | string $rotate = null, boolean $stroke = false ) : Imagick
$str string
$size integer | string
$x integer | string
$y integer | string
$font string
$rotate integer | string
$stroke boolean
Результат Imagick
    public function text($str, $size, $x, $y, $font = null, $rotate = null, $stroke = false)
    {
        $draw = new \ImagickDraw();
        // Set the font if passed
        if (null !== $font) {
            if (!$draw->setFont($font)) {
                throw new Exception('Error: That font is not recognized by the Imagick extension.');
            }
            // Else, attempt to set a basic, default system font
        } else {
            $fonts = $this->resource->queryFonts();
            if (in_array('Arial', $fonts)) {
                $font = 'Arial';
            } else {
                if (in_array('Helvetica', $fonts)) {
                    $font = 'Helvetica';
                } else {
                    if (in_array('Tahoma', $fonts)) {
                        $font = 'Tahoma';
                    } else {
                        if (in_array('Verdana', $fonts)) {
                            $font = 'Verdana';
                        } else {
                            if (in_array('System', $fonts)) {
                                $font = 'System';
                            } else {
                                if (in_array('Fixed', $fonts)) {
                                    $font = 'Fixed';
                                } else {
                                    if (in_array('system', $fonts)) {
                                        $font = 'system';
                                    } else {
                                        if (in_array('fixed', $fonts)) {
                                            $font = 'fixed';
                                        } else {
                                            if (isset($fonts[0])) {
                                                $font = $fonts[0];
                                            } else {
                                                throw new Exception('Error: No default font could be found by the Imagick extension.');
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        $draw->setFont($font);
        $draw->setFontSize($size);
        $draw->setFillColor($this->setColor($this->fillColor));
        if (null !== $rotate) {
            $draw->rotate($rotate);
        }
        if ($stroke) {
            $draw->setStrokeColor($this->setColor($this->strokeColor));
            $draw->setStrokeWidth(null === $this->strokeWidth ? 1 : $this->strokeWidth);
        }
        $draw->annotation($x, $y, $str);
        $this->resource->drawImage($draw);
        return $this;
    }

Usage Example

Пример #1
0
 public function testSystemText()
 {
     $i = new Imagick(__DIR__ . '/../tmp/test.jpg');
     $i->text('Hello World', 36, 10, 100, null, 10, true);
     $this->assertEquals(640, $i->getWidth());
 }