PHP выравнивает центр динамического текста на изображении - PullRequest
0 голосов
/ 07 апреля 2019

Я не могу получить сгенерированный динамический текст с помощью метода GET METHOD для выравнивания по облачному диалоговому окну на изображении ... вы можете увидеть мое прикрепленное изображение ниже, чтобы увидеть, чего я пытаюсь достичь ..

enter image description here

<?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);
?>

Есть способ решить эту проблему, и текст будет меньше, если они длинные?

...