0 က်ဘ်ဆိုက်ဖွံ့ဖြိုးတိုးတက်မှုတွင်ပုံရိပ်ပြုပြင်ခြင်းသည်မျိုးရိုးဗီဇများ,
PHP ကို အသုံးပြု. ထောက်ပံ့ထားသော Image Procession script ကိုမည်သို့ရေးရမည်ကိုဤဆောင်းပါးကဤဆောင်းပါးကသင့်အားသင်ပေးမည်။
ပုံများကိုလုပ်ဆောင်ရန် PHP တွင်အသုံးအများဆုံးစာကြည့်တိုက်သည် GD စာကြည့်တိုက် ( GD extension) ဖြစ်သည်။ သင်မစတင်မီသင်၏ PHP ပတ် 0 န်းကျင်တပ်ဆင်ပြီး GD extensions ကိုဖွင့်ထားကြောင်းသေချာပါစေ။
php -m | grep gd
install မလုပ်ပါက၎င်းကိုသင်အလားတူနည်းလမ်းဖြင့် install လုပ်နိုင်သည် (Ubuntu ကိုဥပမာအဖြစ်ယူပြီး)
sudo apt-get install php-gd
sudo service apache2 restart
ရရှိသော parameters တွေကို (ဥပမာ, ရုပ်ပုံအရွယ်အစား, အရောင် tuning mode)
parameters တွေကိုအပေါ်အခြေခံပြီးတက်ကြွသောအရောင် palette ထုတ်လုပ်ပါ
ပတ်တူဖန်တီးပါ
palette မှရုပ်ပုံများဆွဲပါ
output ကိုသို့မဟုတ်ပုံကိုသိမ်းဆည်းပါ
ဒီနေရာတွင် dynamic palette နှင့်ရိုးရှင်းသော rendering အကျိုးသက်ရောက်မှုများကိုထောက်ပံ့သောအပြည့်အစုံဥပမာတစ်ခုဖြစ်သည်။
<?php
// တုံ့ပြန်မှုခေါင်းစီးကိုသတ်မှတ်ပါ
header('Content-Type: image/png');
// အရောင် palette မျိုးဆက်လုပ်ဆောင်မှုကိုသတ်မှတ်ပါ
function generatePalette($baseColor, $count = 5) {
$palette = [];
list($r, $g, $b) = sscanf($baseColor, "#%02x%02x%02x");
for ($i = 0; $i < $count; $i++) {
$factor = 1 - ($i * 0.15);
$palette[] = sprintf("#%02x%02x%02x",
max(0, min(255, $r * $factor)),
max(0, min(255, $g * $factor)),
max(0, min(255, $b * $factor))
);
}
return $palette;
}
// မှGETအခြေခံအရောင်ဖတ်နေ parameter သည်
$baseColor = isset($_GET['color']) ? $_GET['color'] : '#3498db';
// အရောင် palette ထုတ်လုပ်ပါ
$palette = generatePalette($baseColor);
// ပတ်တူဖန်တီးပါ
$width = 500;
$height = 100;
$image = imagecreatetruecolor($width, $height);
// နောက်ခံဖြည့်ပါ
$white = imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $white);
// အရောင် palette ဆွဲပါ
$segmentWidth = $width / count($palette);
foreach ($palette as $index => $hex) {
list($r, $g, $b) = sscanf($hex, "#%02x%02x%02x");
$color = imagecolorallocate($image, $r, $g, $b);
imagefilledrectangle(
$image,
$index * $segmentWidth,
0,
($index + 1) * $segmentWidth,
$height,
$color
);
}
// မလုပ်မနေရမဟုတ်သော:အရောင်ကုဒ်နံပါတ်ကိုတံဆိပ်ကပ်ပါ
foreach ($palette as $index => $hex) {
$textColor = imagecolorallocate($image, 0, 0, 0);
imagestring(
$image,
3,
$index * $segmentWidth + 10,
$height / 2 - 7,
$hex,
$textColor
);
}
// output ကိုပုံ
imagepng($image);
imagedestroy($image);
?>
အထက်ပါကုဒ်ကို palette.php အဖြစ်သိမ်းထားပါက၎င်းကိုအောက်ပါနည်းလမ်းများဖြင့်ရယူနိုင်သည်။
https://m66.net/palette.php?color=%23e74c3c
၎င်းသည်အနီရောင် ( # E74C3C ) ပေါ်တွင် အခြေခံ. palette ကိုထုတ်ပေးပြီးပုံကိုပြန်ပို့သည်။
output သည် image content ကိုဖြစ်သည့် အချိန်မှစ. html သို့မဟုတ်အာကာသ output ကို script တွင်မဖြစ်စေနိုင်ပါ,
အရောင် palette အရေအတွက်လိုအပ်သကဲ့သို့ပြောင်းလွယ်ပြင်လွယ်ချိန်ညှိနိုင်ပါတယ်။
ပိုမိုရှုပ်ထွေးသော application တစ်ခုအတွက် Gradient, ကျပန်းအရောင်များကဲ့သို့သောအဆင့်မြင့်လုပ်ဆောင်မှုများကိုသင်ထည့်နိုင်သည်။
ဒီဆောင်းပါးကတဆင့်အရောင် palette ကိုဘယ်လိုပုံမှန်ထုတ်လုပ်နိုင်ပြီး PHP ကိုသုံးပြီးပုံတစ်ပုံအဖြစ်ပြန်ဆိုရမယ်ဆိုတာလေ့လာသင်ယူတယ်။ ဤအနည်းငယ်လှည့်ကွက်သည် Avatar Generator, Game Skin Configuration, Theme Color Preview စသည့်ဖြစ်နိုင်ချေအမျိုးမျိုးကိုပြောင်းလွယ်ပြင်လွယ်သွားနိုင်သည်။
အနာဂတ်တွင်, အရောင်သီအိုရီကိုပေါင်းစပ်ခြင်းကဲ့သို့သောအရောင်သီအိုရီကိုပေါင်းစပ်ခြင်း,