التطور للوب بواسطةmysql!PHP - ويلينغ — الصفحة ٤٥٨

474 تولید صور الفصل 19 السرد (19-5-3) showpoll.php - الجزء 3 يجهز الرس سم البياني للبيانات التي ستضاف /******************** Set up base image ***************** // create a blank canvas $im = imagecreate($width, $height); // Allocate colors *****/ $white=ImageColorAllocate($im,255,255,255); $blue=ImageColorAllocate($im,0,64,128); $black=ImageColorAllocate($im,0,0,0); $pink ImageColorAllocate($im,255,78,243); $text_color = $black; $percent_color = $black; $bg_color = $white; $line_color = $black; $bar_color = $blue; $number_color= $pink: // Create "canvas" to draw on ImageFilled Rectangle($im,0,0,$width, $height, $bg_color); // Draw outline around canvas ImageRectangle($im.0,0.$width-1. $height-1, $line_color); // Add title $title = "Poll Results"; $title_dimensions = ImageTTFBBox ($title_size, 0, $font, $title); $title_length = $title_dimensions[2] - $title_dimensions[0]; $title_height = abs($title_dimensions[7] - $title_dimensions[1]); $title_above_line = abs($title_dimensions[7]); $title_x = ($width-$title_length)/2; // center it in x $title_y = ($y - $title_height)/2 + $title_above_line; // center in y gap ImageTTFText($im, $title_size, 0, $title_x, $title_y, $text_color, $font, $title); // Draw a base line from a little above first bar location // to a little below last ImageLine($im, $x, $y-5, $x, $height-15, $line_color); برسم الرسم البياني. في الجزء 3، نقوم بإعداد الصورة الأساسية، ونحجز الألوان، ثم نبدأ نملأ خلفية الرسم البياني هذه المرة باستعمال ImageFilled Rectangle($im,0,0,$width, $height, $bg_color); الدالة ()ImagefilledRectangle، كما قد تتخيّل، ترسم مستطيلاً معبأ. البارامتر الأول هو، كالمعتاد، معرف الصورة. ثم يجب أن نمرّر لها الإحداثيات X و Y لنقطة بداية ونقطة نهاية المستطيل. تلك تتناسب مع الزاوية اليسرى العليا والزاوية اليمنى السفلى، على التوالي. في هذه الحالة، نحن نملأ اللوحة القماشية بأكملها باللون الخلفي، الذي هو البارامتر الأخير، وهو الأبيض.
ص٤٥٨

نص مستخرج آليًا من الصورة، وقد يقع فيه خطأ.