လက်ရှိတည်နေရာ: ပင်မစာမျက်နှာ> နောက်ဆုံးရဆောင်းပါးများစာရင်း> TrueColor ပုံရိပ်တွေတွင် isagecolorallocealpha ကိုသုံးပါ

TrueColor ပုံရိပ်တွေတွင် isagecolorallocealpha ကိုသုံးပါ

M66 2025-06-01

PHP တွင် isionecolorallallalletocatealpha () function ကို alpha (transparency) သတင်းအချက်အလက်များကိုအရောင်ဖြင့်သတ်မှတ်ရန်အသုံးပြုသည်။ သို့သော်၎င်းသည်ဤလုပ်ဆောင်မှုကိုသတိပြုသင့်သည်။ အကယ်. သင်သည် TrueCoecolor Image မဟုတ်သည့်ရုပ်ပုံများကိုအသုံးပြုရန်ကြိုးစားပါက ( imagecreate () ဖန်တီးထားသော palette image)), မမျှော်လင့်သောအပြုအမူသို့မဟုတ်အမှားများကိုသင်ကြုံတွေ့ရနိုင်သည်။

ဒါကြောင့် isionecolorallocatealealpha ၏ function ကိုအသုံးပြုနည်း () ကို trueecolor ပုံများပေါ်တွင်သွယ်ဝိုက်အသုံးပြုရမည်နည်း။ ဤဆောင်းပါးသည်သင့်အား၎င်း၏မူများကိုဖြည့်ဆည်းပေးပြီးလက်တွေ့ကျကျရေးရာသင်္ကေတများပေးလိမ့်မည်။

1 ?? palette ပုံများနှင့်အတူ TrueColor နားလည်ပါ

  • palette-based ပုံရိပ်
    အရောင် 256 ခုအထိသုံးပါ, အရောင်တစ်ခုစီကို palette တွင်သိမ်းဆည်းထားသည်။ imagecreate () အားဖြင့်ဖန်တီးခဲ့သည်။ ရိုးရှင်းသောဂရပ်ဖစ်များအတွက်သင့်တော်သော်လည်းစစ်မှန်သောပွင့်လင်းသောလမ်းကြောင်းများကိုမထောက်ပံ့ပါ။

  • TrueColor Image <br> <br> Pixel တစ်ခုချင်းစီသည် RGB (အနီရောင်, အစိမ်းရောင်, အပြာ) နှင့် alpha (transparency) တန်ဖိုးများကိုလွတ်လပ်စွာသိုလှောင်ထားပါသည်။ () isagecreatetrecolor () မှဖန်တီးခဲ့သည်။ ပွင့်လင်းမြင်သာမှုလိုအပ်သည့်ရှုပ်ထွေးသောဂရပ်ဖစ်နှင့်အခြေအနေများအတွက်သင့်တော်သည်။

imagecolorallocatealpha () alpha channel တစ်ခုပါ 0 င်သောကြောင့်၎င်းတွင် trueecolor image ကိုအကျိုးသက်ရောက်ရန်လိုအပ်သည်။

2 ?? ဖြေရှင်းချက် - TrueColor Image ကိုအရင်ပြောင်းပါ

အကယ်. သင်သည် imageecreate နှင့် palette image ဖြင့်ဖန်တီးခဲ့ပါက, အစအ ဦး ၌သင်က isagecolorallocatealpha () မသုံးမီ၎င်းကို TrueColor Image သို့ပြောင်းလဲနိုင်သည်။

နမူနာကုဒ်

 <?php
// palette image တစ်ခုဖန်တီးပါ
$paletteImage = imagecreate(200, 200);
$white = imagecolorallocate($paletteImage, 255, 255, 255);
$black = imagecolorallocate($paletteImage, 0, 0, 0);

// Palette ပုံရိပ်များကိုပြောင်းပါ truecolor အရုပ်
$truecolorImage = imagecreatetruecolor(imagesx($paletteImage), imagesy($paletteImage));
imagecopy($truecolorImage, $paletteImage, 0, 0, 0, 0, imagesx($paletteImage), imagesy($paletteImage));

// ပွင့်လင်းမြင်သာမှုနှင့်အတူအရောင် assign
$transparentRed = imagecolorallocatealpha($truecolorImage, 255, 0, 0, 64); // 64 Translucet ဖော်ပြသည်

// ဖြည့်စွက်စတုဂံဆွဲရန်ဤအရောင်ကိုသုံးပါ
imagefilledrectangle($truecolorImage, 50, 50, 150, 150, $transparentRed);

// ချိန်ညှိချက်များအဖြစ်သိမ်းဆည်းပါ PNG(ပွင့်လင်းမြင်သာမှု)
header('Content-Type: image/png');
imagepng($truecolorImage);

// မှတ်ဉာဏ်သန့်ရှင်းရေး
imagedestroy($paletteImage);
imagedestroy($truecolorImage);
?>

မှတ်သားရန်အရာ

  • imagecreatetrecolor () ပုံမှန်အားဖြင့်လုံးဝအနက်ရောင်နောက်ခံနှင့်အတူပုံရိပ်တွေဖန်တီးပေးပါတယ်။ အကယ်. သင်သည်မူရင်း palette image ၏နောက်ခံနောက်ခံကိုဆက်လက်ထိန်းသိမ်းထားလိုပါက စိတ်ကူးယဉ် () ကို အသုံးပြုရမည်။

  • output သည် PNG format ဖြင့် alpha channel ကိုသိမ်းရန် (JPEG သည်ပွင့်လင်းမြင်သာမှုကိုမထောက်ခံပါ) ။

  • Transparency Plach alpha သည် 0 (လုံးဝ opaque) မှ 127 (လုံးဝပွင့်လင်းမြင်သာမှု) အထိရှိသည်။

3 ?? နောက်သိကောင်းစရာတစ်ခု - PNG ကိုအခြေခံပုံရိပ်အဖြစ်တိုက်ရိုက်သုံးပါ

 <?php
$image = imagecreatefrompng('https://m66.net/images/sample.png');
$semiTransparentBlue = imagecolorallocatealpha($image, 0, 0, 255, 80);
imagefilledellipse($image, 100, 100, 80, 80, $semiTransparentBlue);

header('Content-Type: image/png');
imagepng($image);
imagedestroy($image);
?>