我无法通过GET方法获取生成的动态文本,以使其与图像中的云对话盒对齐。.您可以在下面看到我的附件图像,以查看我要实现的目标。
<?php
$quote = $_GET["quote"];
$count_quote = strlen($quote);
$count_breakline = explode("\n", $quote);
//Set the Content Type
header('Content-type: image/jpeg');
// Create Image From Existing File
$jpg_image = imagecreatefromjpeg('images/01.jpg');
// Allocate A Color For The Text
$white = imagecolorallocate($jpg_image, 68, 68, 68);
// Set Path to Font File
$font_path = 'fonts/ComicSansMS3.ttf';
// Set Text to Be Printed On Image
$text = $quote;
$box = imageftbbox( 35, 0, $font_path, $text );
// Print Text On Image
if( count($count_breakline) > 1 ) {
if( count($count_breakline) == 2 ) {
imagettftext($jpg_image, 30, 0, 95, 200, $white, $font_path, $count_breakline["0"]);
imagettftext($jpg_image, 30, 0, 95, 200, $white, $font_path, $count_breakline["1"]);
}
if( count($count_breakline) == 3 ) {
imagettftext($jpg_image, 30, 0, 95, 120, $white, $font_path, $count_breakline["0"]);
imagettftext($jpg_image, 30, 0, 95, 165, $white, $font_path, $count_breakline["1"]);
imagettftext($jpg_image, 30, 0, 95, 210, $white, $font_path, $count_breakline["2"]);
}
} else {
if($count_quote <= 17) {
imagettftext($jpg_image, 35, 0, 95, 200, $white, $font_path, $text);
} elseif( ($count_quote >= 18) && ($count_quote <= 21) ) {
imagettftext($jpg_image, 30, 0, 95, 200, $white, $font_path, $text);
}
}
// Send Image to Browser
imagejpeg($jpg_image);
// Clear Memory
imagedestroy($jpg_image);
?>
有一种解决方法,如果文本较长,文本会变小吗?