လက်ရှိတည်နေရာ: ပင်မစာမျက်နှာ> နောက်ဆုံးရဆောင်းပါးများစာရင်း> Imageopenpolygon () သင်္ချာဆိုင်ရာအမြင်အာရုံဆိုင်ရာဇယားများအတွက်၎င်းကိုမည်သို့အသုံးပြုရမည်နည်း (ဥပမာ Pigygon ကားချပ်များကဲ့သို့)

Imageopenpolygon () သင်္ချာဆိုင်ရာအမြင်အာရုံဆိုင်ရာဇယားများအတွက်၎င်းကိုမည်သို့အသုံးပြုရမည်နည်း (ဥပမာ Pigygon ကားချပ်များကဲ့သို့)

M66 2025-05-29

PHP တွင် ImpoPenpolygon () သည်အလွန်လက်တွေ့ကျသောပုံရိပ်ဆွဲခြင်းလုပ်ငန်းဖြစ်သည်။ Polygons ကိုဆွဲရန် Imageopenpolygon () ကို မည်သို့အသုံးပြုရမည်ကိုအသေးစိတ်ရှင်းပြပါလိမ့်မည်။

1 ။ Imageopenpolygon () ?

Imageopenpolygon () PHP GD စာကြည့်တိုက်တွင် function (I.E. , တံခါးပိတ်မဟုတ်သော) Polygon လိုင်းများကိုရေးဆွဲသည့် PHPG GD စာကြည့်တိုက်တွင်လုပ်ဆောင်ချက်တစ်ခုဖြစ်သည်။ ImagePolygon () , Imageopenpolygon နှင့်မတူသည်မှာပထမနှင့်နောက်ဆုံးအချက်များကိုအလိုအလျောက်မချိတ်ဆက်ပါ,

အခြေခံလုပ်ဆောင်ချက်ပုံစံသည်အောက်ပါအတိုင်းဖြစ်သည် -

 bool imageopenpolygon(
    GdImage $image,
    array $points,
    int $num_points,
    int $color
)
  • $ Image : GD Image Image အရင်းအမြစ်။

  • $ ရမှတ်များ - အချက်များ (X1, Y1, X2, Y2, Y2, xn, yn) ။

  • $ numpoints : အချက်များအရေအတွက်။

  • $ အရောင် - အရောင်အမှတ်အသား ( imagecoleallate ()) ) ။

2 ။ Imageopenpolygon ကို ဘယ်လိုသုံးရမလဲ။

(1) အခြေခံပုံရိပ်တစ်ခု ဖန်တီး. polygon ကိုဆွဲပါ

ပင်တဂွန်၏ပွင့်လင်း polyline ဆွဲရန်ရိုးရှင်းသောဥပမာတစ်ခုရှိသည်။

 <?php
// ပတ်တူဖန်တီးပါ
$image = imagecreatetruecolor(400, 400);

// အရောင်များကိုသတ်မှတ်ပါ
$white = imagecolorallocate($image, 255, 255, 255);
$blue = imagecolorallocate($image, 0, 0, 255);

// နောက်ခံဖြည့်ပါ
imagefill($image, 0, 0, $white);

// Polygon Vertices ကိုသတ်မှတ်ပါ (ပင်တမန်,မပိတ်ဘူး)
$points = [
    200, 50,   // ဒေါင်လိုက်1
    350, 150,  // ဒေါင်လိုက်2
    300, 300,  // ဒေါင်လိုက်3
    100, 300,  // ဒေါင်လိုက်4
    50, 150    // ဒေါင်လိုက်5
];

// ဖွင့်လှစ် polygons ဆွဲပါ
imageopenpolygon($image, $points, 5, $blue);

// browser မှ output ကို
header('Content-Type: image/png');
imagepng($image);

// ပုံရိပ်အရင်းအမြစ်များကိုဖျက်ဆီး
imagedestroy($image);
?>

အထက်ပါကုဒ်ကို run ပါ။ ပင်တဂွန်သည်အပြာရောင်အစိတ်အပိုင်းငါးခုဖြင့်ရေးထားသည့်ပင်တဂွန်ကိုတွေ့ရလိမ့်မည်။

(2) ပုံကိုဆာဗာသို့သိမ်းဆည်းပါ

တစ်ခါတစ်ရံပုံရိပ်ကိုဖိုင်တစ်ခုအနေဖြင့်တိုက်ရိုက်ထုတ်ပေးမည့်အစားဖိုင်တစ်ခုအဖြစ်သိမ်းဆည်းလိုသည်။

 <?php
$image = imagecreatetruecolor(400, 400);
$white = imagecolorallocate($image, 255, 255, 255);
$red = imagecolorallocate($image, 255, 0, 0);
imagefill($image, 0, 0, $white);

$points = [
    100, 100,
    300, 100,
    300, 300,
    100, 300
];

imageopenpolygon($image, $points, 4, $red);

// ပုံကို local server သို့သိမ်းဆည်းပါ
imagepng($image, '/var/www/m66.net/uploads/openpolygon.png');

imagedestroy($image);
?>

အထက်ဖော်ပြပါကုဒ်သည်ရေးဆွဲထားသော quadrilateral ကို /var/www/m66.net/uploads/openpolygon.png လမ်းကြောင်းကိုကယ်တင်လိမ့်မည်။

(3) dynamic သင်္ချာဖော်မြူလာနှင့်အတူပေါင်းစပ်အတွက်ညွှန်ပြသမဝါအတ်များကို generate

အကယ်. သင် polygon ၏ပုံသဏ္ဌာန်သည်ပုံမှန်မဟုတ်သော n-side ပုံဆွဲခြင်းစသည့်သင်္ချာဆိုင်ရာဖော်မြူလာများအရပြောင်းလဲရန်ပုံသဏ္ဌာန်ကိုပြောင်းလဲစေလိုပါကသင်လုပ်နိုင်သည်။

 <?php
function generatePolygonPoints($centerX, $centerY, $radius, $sides) {
    $points = [];
    for ($i = 0; $i < $sides; $i++) {
        $angle = 2 * M_PI * $i / $sides;
        $x = $centerX + $radius * cos($angle);
        $y = $centerY + $radius * sin($angle);
        $points[] = $x;
        $points[] = $y;
    }
    return $points;
}

$image = imagecreatetruecolor(500, 500);
$white = imagecolorallocate($image, 255, 255, 255);
$green = imagecolorallocate($image, 0, 128, 0);
imagefill($image, 0, 0, $white);

// တက်ကြွသောမျိုးဆက် 7 ပြင်ပ(七ပြင်ပ)
$points = generatePolygonPoints(250, 250, 200, 7);

imageopenpolygon($image, $points, 7, $green);

// output ကိုပုံ
header('Content-Type: image/png');
imagepng($image);
imagedestroy($image);
?>

ဤနည်းအားဖြင့်သင်သည်မည်သည့်ဘက်မဆိုအနား မဆိုအနား များတွင်မဆိုတုန့်ပြန်မှုများကိုယူနိုင်သည်။

3 ။ မှတ်စုဖို့အရာ

  • Imageopenpolygon () PHP သည် GD စာကြည့်တိုက်ကို install လုပ်ပြီးစွမ်းဆောင်နိုင်ရန်အတွက် GD extension support လိုအပ်သည်။

  • Point Array ၏အရှည်သည် 2 မှတ် ဖြစ်ရမည်။

  • Polygons ကိုပိတ်ရန်လိုအပ်ပါက Imageopenpolygon () အစား ImagePolygon () ကို သုံးပါ။

  • ဖိုင်ကိုသိမ်းဆည်းသောအခါဆာဗာပေါ်ရှိလမ်းညွှန် / -var/www/ m666.net/uploads/ ကိုသေချာအောင်လုပ်ပါ။

4 ။ အကျဉ်းချုပ်

Imageopenpolygon () PHP ရှိသင်္ချာဂရပ်ဖစ်များကိုအလွယ်တကူမြင်ယောင်စေနိုင်သည်။ ၎င်းသည်အခြေခံဂရပ်ဖစ်ပုံဆွဲခြင်းအတွက်သင့်လျော်သည်သာမကကြွယ်ဝသော dynamic display effect များကိုအောင်မြင်ရန်သင်္ချာဖော်မြူလာများနှင့်ပေါင်းစပ်နိုင်သည်။ ၎င်းသည်သင်၏ PHP Image processing နှင့် data visualization စွမ်းရည်ကိုနောက်အဆင့်သို့ပို့ဆောင်နိုင်သည်။