PHP imagefilledarc Function: Drawing and Filling Elliptical Arcs
This article explains the PHP GD library function imagefilledarc, detailing its parameters, return values, and providing a complete example that creates a PNG image with filled elliptical arcs and a simple 3‑D effect.
imagefilledarc is a PHP GD library function that draws a filled elliptical arc on a given image resource.
Parameters resource $image – image resource created by functions such as imagecreatetruecolor(). int $cx – x-coordinate of the center. int $cy – y-coordinate of the center. int $width – width of the ellipse. int $height – height of the ellipse. int $start – start angle in degrees. int $end – end angle; 0° is at three‑o’clock and the arc is drawn clockwise. int $color – color identifier allocated with imagecolorallocate(). int $style – bitwise OR of IMG_ARC_PIE, IMG_ARC_CHORD, IMG_ARC_NOFILL, IMG_ARC_EDGED.
Return value
Returns the image resource on success, or FALSE on failure.
Example
<?php
// Create image
$image = imagecreatetruecolor(100, 100);
// Allocate colors
$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$gray = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
$darkgray = imagecolorallocate($image, 0x90, 0x90, 0x90);
$navy = imagecolorallocate($image, 0x00, 0x00, 0x80);
$darknavy = imagecolorallocate($image, 0x00, 0x00, 0x50);
$red = imagecolorallocate($image, 0xFF, 0x00, 0x00);
$darkred = imagecolorallocate($image, 0x90, 0x00, 0x00);
// 3D effect
for ($i = 60; $i > 50; $i--) {
imagefilledarc($image, 50, $i, 100, 50, 0, 45, $darknavy, IMG_ARC_PIE);
imagefilledarc($image, 50, $i, 100, 50, 0, 45, $darkgray, IMG_ARC_PIE);
imagefilledarc($image, 50, $i, 100, 50, 0, 45, 360, $darkred, IMG_ARC_PIE);
}
imagefilledarc($image, 50, 50, 100, 50, 0, 45, $navy, IMG_ARC_PIE);
imagefilledarc($image, 50, 50, 100, 50, 0, 45, $gray, IMG_ARC_PIE);
imagefilledarc($image, 50, 50, 100, 50, 0, 45, $red, IMG_ARC_PIE);
// Output image
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>The script outputs a PNG image showing several filled arcs that create a simple 3‑D effect.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
