Text::signature

Create a signature text image watermark with Jellyka Saint-Andrew's Queen Truetype Font.

@param string $string
@param int    $size
@param string $color

@return static
5401
public function signature($string, $size = 25, $color = 'ffffff')
    {
        $this->setFontPath(__DIR__ . DIRECTORY_SEPARATOR . 'Fonts/Jellyka_Saint-Andrew\'s_Queen.ttf')
            ->setFontSize($size)
            ->setFontColor($color)
            ->setString($string);

        if ($this->position === 'AUTO') {
            $this->position = 'CENTER';
        }

        return $this;
    }
1073798
public static function writeln($text = '', $text_color = null, $bg_color = null)
    {
        self::write("{$text}\n", $text_color, $bg_color);
    }
166655
public static function hasSignature($string, $signature)
    {
        if (ctype_xdigit($signature) === false) {
            throw new \InvalidArgumentException(sprintf('Invalid HEX signature provided: %s', $signature));
        }
        $signatureChars = str_split($signature, 2);
        $hexChars = array_map(
            function ($val) {
                return strtoupper(bin2hex($val));
            },
            str_split(substr($string, 0, count($signatureChars)))
        );

        return $hexChars === $signatureChars;
    }
383990
public function runExpand(Image $image, $width, $color)
    {
        return $image->resizeCanvas(
            $width * 2,
            $width * 2,
            'center',
            true,
            $color
        );
    }
336357
public static function write(string $string, string $color = null, $appendTime = true)
    {
        parseColor:
        $prefix = $suffix = '';
        if ($color) {
            $color = strtolower(trim($color));
            switch ($color) {
                case 'blue' :
                    $prefix = "\033[44;37;1m";
                    break;
                case 'green' :
                    $prefix = "\033[42;37;1m";
                    break;
                case 'red' :
                    $prefix = "\033[41;37;1m";
                    break;
                case 'yellow' :
                    $prefix = "\033[43;37;1m";
                    break;
                default:
                    $color = 'blue';
                    goto parseColor;
                    break;
            }

            if ($prefix) {
                $suffix = "\033[0m";
            }

            if (strpos($string, '^^') === false) {
                $hasEof = mb_substr($string, -1, 1) === "\n";
                $string = rtrim($string, "\n");
                $string = '^^' . $string . '$$';
                if ($hasEof) {
                    $string .= "\n";
                }
            }

            $string = str_replace(['^^', '$$'], [$prefix, $suffix], $string);
        }

        if (mb_substr($string, -1, 1) !== "\n") {
            $string .= "\n";
        }

        if ($appendTime) {
            $string = '[' . date('m-d H:i:s') . '] ' . $string;
        }

        echo $string;
    }
514384
public function getImageResource($string, $size = 64, $color = null, $backgroundColor = null)
    {
        return $this->generator->getImageResource($string, $size, $color, $backgroundColor);
    }
448140
public static function fromHexString(string $string) : Colour
    {
        list($r, $g, $b) = ColourStringParser::parseHexString($string);

        return new self($r, $g, $b);
    }
887564
public function title(
         string $title,
         int $font_size = 16,
         string $color = '#3D4852',
         bool $bold = true,
         string $font_family = "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"
     ) {
        return $this->options([
            'caption'          => $title,
            'captionFontSize'  => $font_size,
            'captionFontColor' => $color,
            'captionFontBold'  => $bold,
            'captionFont'      => $font_family,
        ]);
    }
716526
public function title(
        string $title,
        int $font_size = 14,
        string $color = '#666',
        string $font_weight = 'bold',
        string $font_family = "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"
    ) {
        return $this->options([
            'title' => [
                'display'    => true,
                'fontFamily' => $font_family,
                'fontSize'   => $font_size,
                'fontColor'  => $color,
                'fontStyle'  => $font_weight,
                'text'       => $title,
            ],
        ]);
    }
1117907
def magenta(cls, string, auto=False):
        
        return cls.colorize('magenta', string, auto=auto)
1109870
public static Font createFont(Workbook workbook, short color, short fontSize, String fontName) {
		final Font font = workbook.createFont();
		return setFontStyle(font, color, fontSize, fontName);
	}
1212033
public static Font setFontStyle(Font font, short color, short fontSize, String fontName) {
		if(color > 0) {
			font.setColor(color);
		}
		if(fontSize > 0) {
			font.setFontHeightInPoints(fontSize);
		}
		if(StrUtil.isNotBlank(fontName)) {
			font.setFontName(fontName);
		}
		return font;
	}
910315
public function createTextWatermark($text, $width, $height, $prefix = 'wm_', $textAngle = -30.0, $textOpacity = 0.4) {
		$imagick = new Imagick($this->dir.$this->filename);
	 	
 	 	$draw = new ImagickDraw();
	 	
	 	//set font size proportional to target image size
	 	$fontSize = min($imagick->getImageWidth(), $imagick->getImageHeight()) * 0.12;
	 	$draw->setFontSize($fontSize);
	 	
	 	//text transparency
	 	$draw->setFillOpacity($textOpacity);
	 	
	 	//write text in specified positions
	 	$draw->setGravity(Imagick::GRAVITY_CENTER);
	 	$imagick->annotateImage($draw, 0, 0, $textAngle, $text);
	 	$draw->setGravity(Imagick::GRAVITY_NORTH);
	 	$imagick->annotateImage($draw, 0, 0, $textAngle, $text);
	 	$draw->setGravity(Imagick::GRAVITY_SOUTH);
	 	
	 	$imagick->annotateImage($draw, 0, 0, $textAngle, $text);
 	
	 	//if image width or height is smaller than requested dimensions, then use the source image size
	 	$width = min($width, $imagick->getImageWidth());
	 	$height = min($height, $imagick->getImageHeight());
	 	if($width < 0 && $height < 0) {
	 		$width = $imagick->getImageWidth();
	 		$height = $imagick->getImageHeight();
	 	}
	 	
 		$bestfit = true;
		if($this->defaultDimension == 'width') {
			$height = 0;
			$bestfit = false;
		} else if($this->defaultDimension == 'height') {
			$width = 0;
			$bestfit = false;
		}
		
		$result = $imagick->thumbnailImage($width, $height, $bestfit);
		if ($result) {
			$thumbName = $this->createThumbName($this->filename, $prefix);
			$imagick->writeImage($this->dir.$thumbName);
			$imagick->clear();
			$imagick->destroy();
		
			return $thumbName;
		}
		
		return false;
	}
657417
public function displayImage($string, $size = 64, $hexaColor = null)
	{
		header("Content-Type: image/png");
		$this->generateImage($string, $size, $hexaColor);
	}
696058
public static function create($color)
    {
        $template = 'Length of hexadecimal value of color \'%s\' is incorrect. It\'s %d, but it should be 3 or 6.'
            . ' Is there everything ok?';

        $message = sprintf($template, $color, strlen($color));

        return new static($message);
    }
482670
public function displayImage($string, $size = 64, $color = null)
	{
		header("Content-Type: image/png");
		$this->generateImage($string, $size, $color);
	}
418596
public function getImgBinary($string, $size = '', $color = '', $bg = '')
    {
        ob_start();
        imagepng($this->getImgResource($string, $size, $color, $bg));

        return ob_get_clean();
    }