CAPTCHA အတည်ပြုချက်ကုဒ်အောင်သည့်အခါ၎င်းသည်အတည်ပြုကုဒ်သည်စက်ကိုအလိုအလျောက်ခွဲခြားသိမြင်ရန်သာမက၎င်းကိုအလွယ်တကူခွဲခြားသတ်မှတ်ရန်ခွင့်မပြုနိုင်စေရန်အတွက်အရေးကြီးသောနည်းပညာဆိုင်ရာအခက်အခဲတစ်ခုဖြစ်ပြီး၎င်းကိုအလွယ်တကူခွဲခြားသတ်မှတ်နိုင်သည်။ PHP သည်ပုံရိပ်များ၏ဆ န့ ်ကျင်ရေးအကျိုးသက်ရောက်မှုကိုထိရောက်စွာတိုးတက်အောင်ပြုလုပ်နိုင်သည့်ကြွယ်ဝသောပုံရိပ်ထုတ်ယူမှုလုပ်ဆောင်မှုကိုပေးသည်။
ဤဆောင်းပါးသည် PHP ၏ GD စာကြည့်တိုက်ကို Captcha Verification Code ကိုထုတ်လုပ်သည့်အခါအတည်ပြုချက်ကုဒ်၏ ရုပ်မြင်သံကြား စာကိုမည်သို့ပြောင်းလဲရန်ပုံစံကိုမည်သို့အသုံးပြုရမည်ကိုသရုပ်ပြပါလိမ့်မည်။
ImageanTias () သည် PHPG GD စာကြည့်တိုက်တွင်ပုံရိပ်များ၏အတိအကျအကျိုးသက်ရောက်မှုကိုဖွင့်ရန်သို့မဟုတ်ပိတ်ရန်သို့မဟုတ်ပိတ်ထားရန်လုပ်ဆောင်သည်။ jagging သည်ပုံ၏အနားအနားများသည် unsmoothed pixel နယ်နိမိတ်များကိုအရှိန်မြှင့်တင်ခြင်းကြောင့်ဖြစ်သည်။ anti-aliasing သည်အစွန်း pixel များကိုချောချောမွေ့မွေ့စေသည်။
function ရှေ့ပြေးပုံစံသည်အောက်ပါအတိုင်းဖြစ်သည် -
bool imageantialias ( resource $image , bool $enable )
$ Image : Image အရင်းအမြစ်လက်ကိုင်
$ enable : eniasing anti-aliasing အကျိုးသက်ရောက်မှုကိုဖွင့ ် သို့မဟုတ် ပိတ်ထား ပါ
အခြေခံအတည်ပြုကုဒ်ကိုပထမ ဦး ဆုံးဖန်တီးကြပါစို့။
<?php
// ပုံတစ်ပုံဖန်တီးပါ 150x50 အလွတ်
$image = imagecreatetruecolor(150, 50);
// အရောင်များကိုသတ်မှတ်ပါ
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
// အဖြူရောင်နှင့်ပြည့်စုံနောက်ခံ
imagefilledrectangle($image, 0, 0, 150, 50, $white);
antialiasing underiasing ကိုဖွင့်ထားသည့်အခါရေးဆွဲထားသောလိုင်းများနှင့်စာသားအနားများချောချောမွေ့မွေ့ဖြစ်လိမ့်မည်။
// anti-aliasing ကိုဖွင့်ပါ
imageantialias($image, true);
ရိုးရှင်းသော OCR အသိအမှတ်ပြုမှုကိုကာကွယ်ရန်အတည်ပြုသည့်ကုဒ်များသို့ 0 င်ရောက်စွက်ဖက်သောလိုင်းများကိုထည့်သွင်းပါ။
for ($i = 0; $i < 5; $i++) {
$line_color = imagecolorallocate($image, rand(100, 150), rand(100, 150), rand(100, 150));
imageline($image, rand(0, 150), rand(0, 50), rand(0, 150), rand(0, 50), $line_color);
}
စာသားဆွဲရန် IgeetteTtext () function ကို အသုံးပြု. စာသားကိုရှင်းလင်းရန် Anti-aliasing ကိုအသုံးပြုသည်။
$font = __DIR__ . '/fonts/arial.ttf'; // ကျေးဇူးပြုပြီး font လမ်းကြောင်းမှန်ကိုသေချာအောင်လုပ်ပါ
$code = substr(str_shuffle('ABCDEFGHJKLMNPQRSTUVWXYZ23456789'), 0, 5);
for ($i = 0; $i < strlen($code); $i++) {
$text_color = imagecolorallocate($image, rand(0, 100), rand(0, 100), rand(0, 100));
imagettftext(
$image,
20,
rand(-15, 15),
20 + $i * 25,
rand(30, 40),
$text_color,
$font,
$code[$i]
);
}
header('Content-Type: image/png');
imagepng($image);
imagedestroy($image);
?>
Imageantialias () ပုံသဏ် and ာန်နှင့်ပုံစံမျိုးစုံများ နှင့်ပုံသဏ် aboves ာန်နှင့်ပုံသဏ် above ာန်များဖြင့်သာအလုပ်လုပ်သည်။
antialiasing ကိုလှည့်ခြင်းက CPU ဝန်ထုပ်ဝန်ပိုးကိုတိုးမြှင့်နိုင်သော်လည်းပုံရိပ်အရည်အသွေးသည်များသောအားဖြင့်တန်ဖိုးရှိသည်။
ဖောင့်ဖိုင်တည်ရှိပြီးလမ်းကြောင်းမှန်ပေါ်သေချာပါစေ။
<?php
// ပုံရိပ်တစ်ခုဖန်တီးပါ
$image = imagecreatetruecolor(150, 50);
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
imagefilledrectangle($image, 0, 0, 150, 50, $white);
// ဆန့်ကျင် aliasing ကို enable
imageantialias($image, true);
// နှောင့်အယှက်လိုင်းများဆွဲပါ
for ($i = 0; $i < 5; $i++) {
$line_color = imagecolorallocate($image, rand(100, 150), rand(100, 150), rand(100, 150));
imageline($image, rand(0, 150), rand(0, 50), rand(0, 150), rand(0, 50), $line_color);
}
// အတည်ပြုကုဒ်စာသား
$font = __DIR__ . '/fonts/arial.ttf';
$code = substr(str_shuffle('ABCDEFGHJKLMNPQRSTUVWXYZ23456789'), 0, 5);
for ($i = 0; $i < strlen($code); $i++) {
$text_color = imagecolorallocate($image, rand(0, 100), rand(0, 100), rand(0, 100));
imagettftext($image, 20, rand(-15, 15), 20 + $i * 25, rand(30, 40), $text_color, $font, $code[$i]);
}
header('Content-Type: image/png');
imagepng($image);
imagedestroy($image);
?>
အထက်ပါဥပမာမှတစ်ဆင့်ပုံသဏ္ဌာန်ရှိသည့် အရောင်များကို ပုံရိပ်ရှိအစရှိသည့်ပုံစံများကိုရှင်းလင်းစွာမြင်နိုင်သည်။ 0 င်ရောက်စွက်ဖက်ခြင်းလိုင်းများနှင့်ပုံပျက်သောစာသားကိုပေါင်းစပ်ခြင်းကအတည်ပြုကုဒ်များ၏လုံခြုံရေးနှင့်အသုံးပြုသူအတွေ့အကြုံကိုထိရောက်စွာတိုးတက်စေနိုင်သည်။
သက်ဆိုင်ရာအရင်းအမြစ်များသို့မဟုတ် apis ရယူရန်လိုအပ်ပါက M66.net ဖြင့် URL domain name ကိုအစားထိုးရန်သင်သတိပြုပါ။