Friday, September 5, 2025
HomeLanguagesPHP | GmagickDraw arc() Function

PHP | GmagickDraw arc() Function

The GmagickDraw::arc() function is an inbuilt function in PHP which is used to draw an arc falling within a specified bounding rectangle on the image. 

Syntax: 
 

GmagickDraw GmagickDraw::arc( float $sx, float $sy,
              float $ex, float $ey, float $sd, float $ed )

 Parameters: This function accept six parameters as mentioned above and described below: 

  • $sx: It specifies the starting x-ordinate of rectangle.
  • $sy: It specifies the starting y-ordinate of rectangle.
  • $ex: It specifies the ending x-ordinate of rectangle.
  • $ey: It specifies the ending y-ordinate of rectangle.
  • $sd: It specifies the starting degrees of rotation.
  • $ed: It specifies the ending degrees of rotation.

 

Return Value: This function returns GmagickDraw object on success. 

Exceptions: This function throws GmagickDrawException on error. 

Below given programs illustrate the GmagickDraw::arc() function in PHP: 

 

Used Image:

Program 1 (Drawing arc from scratch): 

PHP




<?php
  
// Create a new Gmagick object
$gmagick = new Gmagick('neveropen.png');
   
// Create a GmagickDraw object
$draw = new GmagickDraw();
   
// Set the color
$draw->setFillColor('white');
   
// Function to draw rectangle
$draw->rectangle(0, 0, 800, 400);
   
// Set the fill color
$draw->setFillColor('white');
  
// Set the stroke color
$draw->setstrokecolor('black');
  
// Set the stroke width
$draw->setStrokeWidth(5); 
   
// Mark a arc
$draw->arc(60, -60, 460, 170, 0, 200);
   
// Use of drawimage function
$gmagick->drawImage($draw);
   
// Display the output image
header("Content-Type: image/png");
echo $gmagick->getImageBlob();
?>


Output: 

 

Program 2 (Drawing arc on a image): 

php




<?php
  
// Create a new Gmagick object
$gmagick = new Gmagick('neveropen.png');
    
// Create a GmagickDraw object
$draw = new GmagickDraw();
    
// Set the fill color
$draw->setFillColor('red');
   
// Set the stroke color
$draw->setstrokecolor('green');
   
// Set the stroke width
$draw->setStrokeWidth(5); 
    
// Mark a arc
$draw->arc(160, -60, 360, 170, 50, 200);
    
// Use of drawimage function
$gmagick->drawImage($draw);
    
// Display the output image
header("Content-Type: image/png");
echo $gmagick->getImageBlob();
?>


Output: 

Reference: https://www.php.net/manual/en/gmagickdraw.arc.php

RELATED ARTICLES

Most Popular

Dominic
32269 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6637 POSTS0 COMMENTS
Nicole Veronica
11802 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11865 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7027 POSTS0 COMMENTS
Thapelo Manthata
6704 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS