
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
How to draw a partial arc and fill it using imagefilledarc() function in PHP?
imagefilledarc() is an inbuilt function in PHP that is used to draw a partial arc and fill it.
Syntax
bool imagefilledarc($image, $cx, $cy, $width, $height, $start, $end, $color, $style)
Parameters
imagefilledarc() takes nine parameters: $image, $cx, $cy, $width, $height, $start, $end, $color, and $style.
$image − It is returned by the image creation function imagecreatetruecolor(). This function is used to create the size of the image.
$cx − Sets the x-coordinate of the center.
$cy − Sets the y-coordinate of the center.
$width − Sets the arc width.
$height − Sets the arc height.
$start − Start angle in degrees.
$end − Arc end angle, in degrees. 00 is located at the three o'clock position, and the arc is drawn clockwise.
$color − It is a color identifier created with imagecolorallocate() function.
$style − Suggests how to fill the image and its values can be anyone from the following list −
IMG_ARC_PIE
IMG_ARC_CHORD
IMG_ARC_NOFILL
IMG_ARC_EDGED
Both IMG_ARC_PIE and IMG_ARC_CHORD are mutually exclusive.
IMG_ARC_CHORD connects a straight line from the starting and ending angles, while IMG_ARC_PIE produces a rounded edge.
IMG_ARC_NOFILL indicates that the arc or chord should be outlined, not filled.
IMG_ARC_EDGED is used together with the IMG_ARC_NOFILL, indicates that the beginning and ending angles should be connected to the center.
Return Values
It returns True on success and False on failure.
Example 1
<?php define("WIDTH", 700); define("HEIGHT", 550); // Create the image. $image = imagecreate(WIDTH, HEIGHT); // Allocate colors. $bg = $white = imagecolorallocate($image, 0x00, 0x00, 0x80); $gray = imagecolorallocate($image, 122, 122, 122); // make pie arc. $center_x = (int)WIDTH/2; $center_y = (int)HEIGHT/2; imagerectangle($image, 0, 0, WIDTH-2, HEIGHT-2, $gray); imagefilledarc($image, $center_x, $center_y, WIDTH/2, HEIGHT/2, 0, 220, $gray, IMG_ARC_PIE); // Flush image. header("Content-Type: image/gif"); imagepng($image); ?>
Output
Example 2
<?php // Created the image using imagecreatetruecolor function. $image = imagecreatetruecolor(700, 300); // Allocated the darkgray and darkred colors $darkgray = imagecolorallocate($image, 0x90, 0x90, 0x90); $darkred = imagecolorallocate($image, 0x90, 0x00, 0x00); // Make the 3D effect for ($i = 60; $i > 50; $i--) { imagefilledarc($image, 100, $i, 200, 100, 75, 360, $darkred, IMG_ARC_PIE); } imagefilledarc($image, 100, $i, 200, 100, 45, 75 , $darkgray, IMG_ARC_PIE); // flush image header('Content-type: image/gif'); imagepng($image); imagedestroy($image); ?>
Output
- Related Articles
- How to draw a line using imageline() function in PHP?
- How to draw a string vertically using imagestringup() function in PHP?
- How to draw an ellipse using imageellipse() function in PHP?
- How to draw a filled polygon using an imagefilledpolygon() function in PHP?
- How to draw a text string image horizontally by using imagestring() function in PHP?
- How to draw a filled arc in Matplotlib?
- Flood fill to specific color in PHP using imagefilltoborder() (GD) function.
- How to draw an open polygon using the imageopenpolygon() function n PHP?
- How to draw a circle with arc() in HTML5?
- How to draw an arc on a tkinter canvas?
- How to get resource ID using get_resource_id() function in PHP and PHP 8?
- How to set a single pixel using imagesetpixel() function in PHP?
- How to apply a filter to an image using imagefilter() function in PHP?
- Arc function in C
- How to destroy an image in PHP using imagedestroy() function?
