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

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();
}

Lại Đình Cường

Tôi làm quen và phát triển WordPress từ năm 2008, cho đến nay thì đã có hơn 13 năm kinh nghiệm, thật không thể tin được. Tôi có đam mê và dành nhiều thời gian làm việc với WordPress mỗi ngày, hiện tại tôi đang phát triển giao diện và plugin cho WordPress.

Nếu bạn đang cần người làm trang web bằng WordPress? Hãy liên hệ với tôi ngay để được tư vấn nhé.