PHP တွင် Image processing library gd သည်အင်အားကြီးမားသောလုပ်ဆောင်မှုများစွာကိုထောက်ပံ့ပေးသည် ။ ၎င်းကိုပုံရိပ်များအတွက်ပွင့်လင်းမြင်သာမှုနှင့်အရောင်များကိုဖန်တီးရန်မကြာခဏအသုံးပြုလေ့ရှိသည်။ GIF Animations များနှင့်အလုပ်လုပ်သောအခါ၎င်းသည်အထူးသဖြင့်သင် semi-transparent semi-transparent သက်ရောက်မှုများကို gif animation မှ frame တစ်ခုသို့ထည့်သွင်းရန်လိုအပ်ပါကအလွန်အသုံးဝင်သည်။ ဤဆောင်းပါးသည် translucc သက်ရောက်မှုဘောင်များရရှိရန် imagecolorallocealealpha () function နှင့် gif anime ကိုမည်သို့အသုံးပြုရမည်ကိုမိတ်ဆက်ပေးလိမ့်မည်။
အဆိုပါ imagecolorallalletocatealpha () function ကိုပုံရိပ်တစ်ခုသို့ပွင့်လင်းမြင်သာမှုနှင့်အတူအရောင်တစ်ခုသတ်မှတ်ရန်အသုံးပြုသည်။ ၎င်း၏ function ကိုလက်မှတ်သည်အောက်ပါအတိုင်းဖြစ်သည် -
int imagecolorallocatealpha ( resource $image , int $red , int $green , int $blue , int $alpha )
$ Image : အရောင်သတ်မှတ်ရန်ပုံရိပ်အရင်းအမြစ်။
$ အနီရောင် , $ အစိမ်းရောင် , $ အပြာ : အရောင်၏ RGB တန်ဖိုး။
$ Alpha : Transparency 0 (လုံးဝမအောင်မြင်) မှ 127 အထိ (လုံးဝပွင့်လင်းမြင်သာမှု) အထိ။
Imagecolorallocatealpha () ဖန်တီးထားသောအရောင်များ () ပုံရိပ်၏ pixels တွင် chrowcent သက်ရောက်မှုများကို Enable လုပ်ပါ။ ၎င်းသည် gif animation တိုင်းအတွက်အလွန်ထိရောက်စေသည်။
GIF Animation ကိုယ်တိုင်ကပွင့်လင်းမြင်သာသော pixels (ပွင့်လင်းမြင်သာသောနောက်ခံ) ကိုထောက်ပံ့သည်။ Gradients ၏ပွင့်လင်းမြင်သာမှုအကျိုးသက်ရောက်မှုကိုရရှိရန်ကျွန်ုပ်တို့သည်ဘောင်တစ်ခုစီကိုလုပ်ဆောင်ရန်နှင့် pixel တစ်ခုစီ၏ပွင့်လင်းမြင်သာမှုကိုတဖြည်းဖြည်းညှိရန်လိုအပ်သည်။
အောက်ဖော်ပြပါအချက်များသည် frame တစ်ခုချင်းစီအတွက် Translucent အကျိုးသက်ရောက်မှုကိုထည့်သွင်းရန် စိတ်ကူးယဉ် ပုံနှင့် gif anime ကိုမည်သို့အသုံးပြုရမည်ကိုပြသသည့်နမူနာကုဒ်ဖြစ်သည်။
<?php
// ဖတ် GIF ရုပ်ရှင်ဓာတ်ပုံများ
$imagePath = 'path_to_your_gif.gif'; // သင့်ကိုယ်ပိုင်နှင့်အစားထိုးပါ GIF ဖိုင်လမ်းကြောင်း
$image = imagecreatefromgif($imagePath);
// ရယူ GIF ၏အရွယ်အစား
$width = imagesx($image);
$height = imagesy($image);
// ပုံရိပ်အရင်းအမြစ်အသစ်တစ်ခုဖန်တီးပါ,ပွင့်လင်းမြင်သာမှု
$newImage = imagecreatetruecolor($width, $height);
// နောက်ခံကိုပွင့်လင်းစေပါ
imagesavealpha($newImage, true);
$transparency = imagecolorallocatealpha($newImage, 0, 0, 0, 127); // လုံးဝပွင့်လင်းနောက်ခံအရောင်များကိုသတ်မှတ်ပါ
imagefill($newImage, 0, 0, $transparency);
// ဖတ်每一အရိုးစု并添加透明效果
for ($frame = 0; $frame < 10; $frame++) { // ယူဆချက် GIF ရုပ်ရှင်ဓာတ်ပုံများ有 10 အရိုးစု
// ရယူ每一အရိုးစု
$frameImage = imagecreatefromgif($image);
// ရယူ每一အရိုးစု的透明颜色
$alpha = 64; // ပွင့်လင်းမြင်သာမှုအဆင့်ကိုသတ်မှတ်ပါ,ဥပမာအားဖြင့် 64 Translucet ဖော်ပြသည်
$transparentColor = imagecolorallocatealpha($frameImage, 255, 0, 0, $alpha);
// 将每一အရိုးစု的透明颜色应用到新的图像
imagefilledrectangle($newImage, 0, 0, $width, $height, $transparentColor);
// 将处理后的အရိုးစု保存到新图像
imagecopy($newImage, $frameImage, 0, 0, 0, 0, $width, $height);
// ပုံကိုသိမ်းဆည်းပါ
imagegif($newImage, 'new_gif.gif'); // ပွင့်လင်းအကျိုးသက်ရောက်မှုနှင့်အတူအသစ် GIF သတ်မှတ်ထားသောတည်နေရာကိုသိမ်းဆည်းပါ
}
// သန့်ရှင်းရေးလုပ်သည်
imagedestroy($image);
imagedestroy($newImage);
?>
GIF File ကိုဖတ်ပါ ။ GIF Animation ကိုဖတ်ရန် imagecreat နာရီ () function ကိုသုံးပါ။
ပုံအသစ်တစ်ခုဖန်တီးပါ ။ ImagecreatetRuecolor () မှတဆင့် ပွင့ ်လင်းမြင်သာမှုအထောက်အပံ့ကို အသုံးပြု. ပုံကြမ်းအရင်းအမြစ်အသစ်တစ်ခုဖန်တီးပါ။
Transparent နောက်ခံကိုသတ်မှတ်ပါ ။
frame တစ်ခုချင်းစီအတွက် process : gif animation တစ်ခုချင်းစီကို frame တစ်ခုစီကို စိတ်ကူးယဉ် () ကို အသုံးပြု. ပုံအသစ်တစ်ခုစီကိုကူးယူပြီး imageflectedanglemangle () ကို သုံး. translucent အကျိုးသက်ရောက်မှုကိုထည့်ပါ။
လုပ်ငန်းစဉ်ပုံရိပ်ကိုသိမ်းဆည်းပါ ။
GIF Animation Frame နံပါတ် - အထက်ပါကုဒ်နံပါတ်တွင် GIF Animation တွင်ဘောင် 10 ခုရှိပြီး၎င်းကိုအမှန်တကယ်အသုံးပြုသောအခါ GIF Animation ၏ဘောင်များအရချိန်ညှိရန်လိုအပ်သည်။
ပွင့်လင်းမြင်သာမှုအဆင့် - သင်၏လိုအပ်ချက်များအရပွင့်လင်းမြင်သာမှုတန်ဖိုးကိုသင်ညှိနိုင်သည်။ Imagecolorallocatealpha ၏ပွင့်လင်းမြင်သာမှုပြဌာန်းချက် () သည် 0 မှ 127 အထိရှိပြီး 0 မှ 127 အထိရှိသည်။
စွမ်းဆောင်ရည်ထည့်သွင်းစဉ်းစားမှုများ - GIF Animations များသည်များသောအားဖြင့်ဘောင်များမျိုးစုံပါ 0 င်ပြီး frame တစ်ခုစီ၏ပွင့်လင်းမြင်သာမှုကိုပြုပြင်ခြင်း,
ISEACOLOROLOCATELOULEALEALEATHA () function ကိုမှတစ်ဆင့် gif animation တစ်ခုချင်းစီကို frame တစ်ခုချင်းစီကိုအလွယ်တကူထည့်နိုင်သည်။ ၎င်းသည်ကျွန်ုပ်တို့အားကာတွန်းသက်ရောက်မှုများပိုမိုအမြင်အာရုံဆိုင်ရာသက်ရောက်မှုများပိုမိုများပြားစေနိုင်သည်။ PHP တွင်ပွင့်လင်းမြင်သာသောသက်ရောက်မှုများကိုကိုင်တွယ်ရန် GD စာကြည့်တိုက်ကိုမည်သို့အသုံးပြုရမည်ကိုပိုမိုနားလည်ရန်ဤဆောင်းပါးသည်သင့်အားပိုမိုကောင်းမွန်သောနားလည်မှုကိုပိုမိုနားလည်ရန်မျှော်လင့်ပါသည်။