PHP တွင် ImagesDringUp () function ကိုပုံရိပ်တစ်ခုပေါ်တွင်ဒေါင်လိုက်ဆွဲရန်အသုံးပြုသည်။ ၎င်းသည် စိတ်ကူးယဉ်ဆန်သော () နှင့်ဆင်တူသည်, သို့သော်ရေးဆွဲထားသောစာသားသည်အလှည့်အလှည့်စာသားသက်ရောက်မှုဖြင့်ပုံများကိုထုတ်လုပ်သည့်အခါအလွန်လက်တွေ့ကျသည်။ သို့သော်စာသားကိုတိုက်ရိုက် ပုံဆွဲခြင်း ()) ကို တိုက်ရိုက်ဆွဲယူသောအခါစာသား၏အပြင်အဆင်နှင့်ချိန်ညှိမှုသည်စာသား၏ layout နှင့် alignment ကိုမကြာခဏ developer မှထိန်းချုပ်ရန်လိုအပ်သည်။ ဤအချိန်တွင် ImageFontwidth () function သည်လွယ်ကူစွာတွက်ချက်ရန်လွယ်ကူစွာတွက်ချက်ရန်လွယ်ကူစွာပိုမိုကောင်းမွန်စွာတွက်ချက်ရန်,
စိတ်ကူးယဉ်ဆန်သော ()
ပုံတစ်ပုံတွင်ဒေါင်လိုက်ကြိုးများဆွဲရန်အသုံးပြုသည်။
bool imagestringup(resource $image, int $font, int $x, int $y, string $string, int $color);
၎င်းတို့အနက် $ ဖောင့် သည် built-in font size (1 ~ 5), $ x က $ y က $ y က start ကိုသွဒီနိတ်ပါ, $ string သည် စာသားအကြောင်းအရာဖြစ်သည်။
imagefontwidth ()
သတ်မှတ်ထားသော built-in font အရွယ်အစား၏ဇာတ်ကောင်အကျယ်ကိုပြန်ပို့ပါ။
int imagefontwidth(int $font);
ဤလုပ်ဆောင်မှုနှစ်ခုကိုအသုံးပြုခြင်းသည်စာသားသို့မဟုတ်မမှန်ပုံစံကိုကျော်လွှားခြင်းကိုရှောင်ရှားရန်, စာသားကိုဆွဲယူသောအခါစာသား၏အနေအထားကိုထိန်းချုပ်နိုင်သည်။
angfeedretringup () သည် စာသားကိုဒေါင်လိုက်ရေးဆွဲခြင်းကတည်းကအလျားလိုက်အကွာအဝေးကိုသတ်မှတ်သည်, သို့သော်ဇာတ်ကောင်အကျယ်ကိုတွက်ချက်ခြင်းမရှိပါက, ထို့ကြောင့်ဖောင့်၏ဇာတ်ကောင်အကျယ်ကို imagefontwidth () ဇာတ်ကောင်တစ် ဦး ချင်းစီ၏ပုံဆွဲအနေအထားကိုတွက်ချက်ရန်နှင့်ကျိုးကြောင်းဆီလျော်သောစာသားကိုတွက်ချက်ရန်နှင့်သင့်တင့်သောစာသားအဆင်အပြင်ကိုအသုံးပြုပါ။
ကျွန်ုပ်တို့သည်ပုံတစ်ပုံတွင်ဒေါင်လိုက်ဆွဲယူလိုပါက 200 pixel 200 pixel များနှင့်အလျားလိုက်ဗဟိုပြုညှိနှိုင်းမှုကိုရရှိရန်ကျွန်ုပ်တို့ဆွဲဆောင်လိုသည်ဆိုပါစို့။
<?php
// အလွတ်တစ်ခုဖန်တီးပါ
$width = 200;
$height = 100;
$image = imagecreatetruecolor($width, $height);
// အရောင်များကိုသတ်မှတ်ပါ
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
// နောက်ခံအရောင်ကိုဖြည့်ပါ
imagefill($image, 0, 0, $white);
$text = "Hello";
$font = 5; // built-in စာလုံးအရွယ်အစား 1~5
// စာသားအကျယ်တွက်ချက်
$fontWidth = imagefontwidth($font);
$textWidth = strlen($text) * $fontWidth;
// တွက်ချက်မှုစတင် x ညီညာစေ,ဗဟိုအဆင့်ကိုအောင်မြင်ရန်
$x = ($width - $textWidth) / 2;
// y ညီညာစေ从底部开始向上绘制
$y = 80;
// အသုံးပြု imagestringup() ဒေါင်လိုက်စာသားဆွဲပါ
imagestringup($image, $font, $x, $y, $text, $black);
// output ကိုပုံ
header("Content-Type: image/png");
imagepng($image);
imagedestroy($image);
?>
စာလုံးတစ်လုံးစီကိုစာလုံးတစ်လုံးစီ၏အကျယ်ကို imagefontwidth ($ font) ဖြင့်ရယူပါ။
ခြုံငုံစာသားအကျယ်ရရန် string ကိုအရှည်ဖြင့်မြှောက်ပါ။
စာသားအကျယ်ကို image width ဖြင့်နုတ်ပါ။ စာသားစင်တာကိုအလျားလိုက်ရေးရန် 2 ကို 2 ဖြင့်ခွဲပါ။
ImagesDringUp () ၏သွဒီန်ဒြေတို့တွင် X သည် စာသား၏ဘယ်ဘက်အစွန်းဖြစ်သည် ။
အကယ်. သင်သည်လက်ဝဲမှစီစဉ်ပေးသောစာသားမျိုးစုံကိုဆွဲဆောင်ခြင်းကဲ့သို့သောဒေါင်လိုက်စာသားမျိုးစုံကိုဆွဲယူရန်လိုအပ်ပါကအစိတ်အပိုင်းတစ်ခုစီ၏ width ကိုတွက်ချက်ရန်နှင့် x ကိုသွဒီနိတ်များကိုထိန်းညှိရန်အတွက် imagefontwidth () ကို သုံးနိုင်သည်။
<?php
$width = 300;
$height = 150;
$image = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
imagefill($image, 0, 0, $white);
$font = 4;
$texts = ["PHP", "Imagestringup", "Example"];
// စုစုပေါင်းအကျယ်တွက်ချက်
$fontWidth = imagefontwidth($font);
$totalWidth = 0;
foreach ($texts as $t) {
$totalWidth += strlen($t) * $fontWidth + 10; // တစ်ခုချင်းစီကိုကြားကာလ10pixels
}
$totalWidth -= 10; // နောက်ဆုံးတစ်ခုအကွာအဝေးမဟုတ်ပါဘူး
// စက်နှိုး x ညီညာစေ居中
$x = ($width - $totalWidth) / 2;
$y = 130;
foreach ($texts as $t) {
imagestringup($image, $font, $x, $y, $t, $black);
$x += strlen($t) * $fontWidth + 10;
}
header("Content-Type: image/png");
imagepng($image);
imagedestroy($image);
?>
၎င်းသည်ဒေါင်လိုက်စာသားမျိုးစုံနှင့်ကိုက်ညီမှုနှင့်ချိန်ညှိမှုကိုပြောင်းလွယ်ပြင်လွယ်ထိန်းချုပ်ရန်ခွင့်ပြုသည်။