လက်ရှိတည်နေရာ: ပင်မစာမျက်နှာ> နောက်ဆုံးရဆောင်းပါးများစာရင်း> Image Closping ပြီးနောက် impegetcclip မှတဆင့်စာသားရေစာများထည့်သွင်းနည်း

Image Closping ပြီးနောက် impegetcclip မှတဆင့်စာသားရေစာများထည့်သွင်းနည်း

gitbox 2025-05-28

1 ။ IgrogetCyp ကဘာလဲ။

ImageGetClip သည် built-in PHP function မဟုတ်ပါ, ၎င်းသည်ယေဘုယျအားဖြင့်ရုပ်ပုံသီးနှံစိုက်ပျိုးခြင်းအတွက်အသုံးပြုသူသတ်မှတ်ထားသော function တစ်ခုဖြစ်သည်။ ဤဆောင်းပါး၏လုပ်ဆောင်ချက်များကိုနားလည်သဘောပေါက်ရန်အတွက်ကျွန်ုပ်တို့သည် accountclip () function ကိုသတ်မှတ်ရန်အတွက်အရင်းအမြစ်ပုံရိပ်မှစတုဂံဒေသများကိုဖြတ်တောက်ရန်ရည်ရွယ်သည်။

2 ။ သီးနှံစိုက်ပျိုးခြင်းနှင့်ရေစာများထည့်သွင်းခြင်းလုပ်ငန်းစဉ်ကိုနားလည်သဘောပေါက်ခြင်း

ပြီးပြည့်စုံသောအဆင့်များမှာအောက်ပါအတိုင်းဖြစ်သည် -

  1. အရင်းအမြစ်မြေပုံကို load လုပ်ပါ။

  2. ပုံကိုဖြတ်ပစ်ပါ။

  3. စာသားရေစာထည့်ပါ။

  4. ပုံရိပ်ကို output ကိုသို့မဟုတ်သိမ်းဆည်းပါ။

အောက်တွင်ပြီးပြည့်စုံသောကျင့်ထုံးဥပမာဖြစ်သည်။

 <?php

function imagegetclip($src_path, $x, $y, $width, $height) {
    $src = imagecreatefromjpeg($src_path);
    $clip = imagecreatetruecolor($width, $height);
    imagecopy($clip, $src, 0, 0, $x, $y, $width, $height);
    return $clip;
}

function addTextWatermark($image, $text, $fontSize = 12, $color = [255, 255, 255], $x = 10, $y = 20) {
    $textColor = imagecolorallocate($image, $color[0], $color[1], $color[2]);
    imagestring($image, $fontSize, $x, $y, $text, $textColor);
    return $image;
}

// နမူနာ:ပုံရိပ်တွေ processing
$source_image = 'https://gitbox.net/images/sample.jpg';
$temp_path = '/tmp/temp.jpg';
file_put_contents($temp_path, file_get_contents($source_image));

$clip = imagegetclip($temp_path, 100, 100, 300, 200);
$clip_with_watermark = addTextWatermark($clip, 'gitbox.netအထူးအခွင့်အရေးရှိသော');

header('Content-Type: image/jpeg');
imagejpeg($clip_with_watermark);
imagedestroy($clip_with_watermark);
?>

3 ။ ရှင်းပြချက်

  • Image ImageGetClip () function ကိုမူရင်းပုံမှသတ်မှတ်ထားသော area ရိယာကိုကလစ်များသည်။

  • addtextwidmatematmermatmermarmarmarmarmarmarmarmarmarmarmarmarmarmarmarmarme () function ကို function;

  • အခြေခံဖောင့်များသည် () ကို အသုံးပြု. () ကို အသုံးပြု. ထည့်သွင်းထားသည်။ အကယ်. သင်သည်စိတ်ကြိုက်ဖောင့်များနှင့်စတိုင်လ်များကိုအသုံးပြုရန်လိုအပ်ပါက Igeetttext () ကို အသုံးပြုရန်အကြံပြုသည်။

  • ဝေးလံခေါင်သီသောပုံများကို file_get_contents မှတဆင့်ယာယီလမ်းညွှန်သို့ဒေါင်းလုပ်လုပ်ထားသည်။

  • server သည် GD extension ကိုဖွင့်ရမည်ကိုသတိပြုပါ။

4 ။ ဖြည့်စွက်: Watermark စာသားကိုအလှဆင်ရန်စိတ်ကြိုက်စာလုံးများကိုသုံးပါ

 imagettftext($image, 16, 0, 10, 30, $textColor, '/path/to/font.ttf', 'gitbox.netအထူးအခွင့်အရေးရှိသော');

ဤကုဒ်သည်လှပသောရေစာရိတ္တစာသားကိုပိုမိုကောင်းမွန်အောင်ပြုလုပ်ရန် TTF ဖောင့်ကိုအသုံးပြုသည်။ ဖောင့်လမ်းကြောင်းသည်တရားဝင်ဖြစ်ပြီးတရုတ်သို့မဟုတ်လိုအပ်သောဇာတ်ကောင်အစုံများကိုလည်းအထောက်အကူပြုကြောင်းသေချာပါစေ။