English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
imagecolorallocatealpha — تخصيص لون وشفافية الصورة.
int imagecolorallocatealpha ( resource $image , int $red , int $green , int $blue , int $alpha )
سلوك imagecolorallocatealpha() متشابه مع imagecolorallocate()، لكنه يحتوي على ميزة إضافية هي معامل الشفافية alpha، والذي يمتد من 0 إلى 127. 0 يعني شفافية كاملة، و127 يعني شفافية تامة.
إذا فشلت التخصيص فيرجع FALSE.
ملاحظة:هذا الدالة تحتاج إلى إصدار GD 2.0.1 أو أعلى (يُنصح بإصدار 2.0.28 أو أعلى).
<?php $size = 300; $image=imagecreatetruecolor($size, $size); // بخلفية بيضاء وحدود سوداء يرسم مربع $back = imagecolorallocate($image, 255, 255, 255); $border = imagecolorallocate($image, 0, 0, 0); imagefilledrectangle($image, 0, 0, $size - 1, $size - 1, $back); imagerectangle($image, 0, 0, $size - 1, $size - 1, $border); $yellow_x = 100; $yellow_y = 75; $red_x = 120; $red_y = 165; $blue_x = 187; $blue_y = 125; $radius = 150; // تخصيص بعض الألوان باستخدام قيمة alpha $yellow = imagecolorallocatealpha($image, 255, 255, 0, 75); $red = imagecolorallocatealpha($image, 255, 0, 0, 75); $blue = imagecolorallocatealpha($image, 0, 0, 255, 75); // رسم ثلاثة دوائر تلتقي imagefilledellipse($image, $yellow_x, $yellow_y, $radius, $radius, $yellow); imagefilledellipse($image, $red_x, $red_y, $radius, $radius, $red); imagefilledellipse($image, $blue_x, $blue_y, $radius, $radius, $blue); // لا تنسى إرسال الـ header الصحيح! header('Content-type: image/png'); // النتيجة النهائية imagepng($image); imagedestroy($image); ?>
صورة النتيجة للنصائح أعلاه كالتالي:
imagecolorallocate() تخصيص لون للصورة.
imagecolordeallocate() إلغاء تخصيص لون الصورة.