Chuyển đổi văn bản thành hình ảnh áp dụng font chữ kèm theo

Lại Đình Cường

Tài liệu thiết kế website

header( "Content-type: image/png" );

if ( class_exists( 'Imagick' ) ) {
	$width  = 1360;
	$height = 400;

	$s = 60;

	$fontfile = __DIR__ . '/font.ttf';

	$x = 50;
	$y = 150;
	$t = 'Agenda Fantasy Halloween Font';

	// Create a new Imagick object
	$image = new Imagick();
	// Set the image background color
	$backgroundColor = new ImagickPixel( 'white' );
	$image->newImage( $width, $height, $backgroundColor );

	// Create a new drawing object
	$draw = new ImagickDraw();
	$draw->setFont( $fontfile );
	$draw->setFontSize( $s );

	// Set the font color
	$textColor = new ImagickPixel( 'black' );
	$draw->setFillColor( $textColor );

	// Set font features for ligatures and kerning
	$fontFeatures = "liga=1,kern=1"; // Enable ligatures and kerning
	$draw->setTextEncoding( 'UTF-8' );
	$image->setFont( $fontfile );
	$image->drawImage( $draw );

	$image->annotateImage( $draw, $x, $y, 0, $t );
	$image->setImageFormat( 'png' );
	echo $image->getImageBlob();
}
0 0 đánh giá
Đánh giá bài viết
Theo dõi
Thông báo của
guest
0 Góp ý
Cũ nhất
Mới nhất Được bỏ phiếu nhiều nhất