Thursday, July 30, 2026
HomeLanguagesPHP | GmagickDraw getstrokecolor() Function

PHP | GmagickDraw getstrokecolor() Function

The GmagickDraw::getstrokecolor() function is an inbuilt function in PHP which is used to get the color used for stroking object outlines.

Syntax:

ImagickPixel GmagickDraw::getstrokecolor( void )

Parameters: This function doesn’t accept any parameters.

Return Value: This function returns an GmagickPixel value containing the color.

Exceptions: This function throws GmagickDrawException on error.

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

Program 1:




<?php  
  
// Create a new GmagickDraw object 
$draw = new GmagickDraw(); 
  
// Get the stroke color 
$strokeColor = $draw->getstrokecolor()->getcolor(); 
echo $strokeColor
?> 


Output:

rgb(0, 0, 0)

Program 2:




<?php  
  
// Create a new GmagickDraw object 
$draw = new GmagickDraw(); 
  
// Set the stroke color
$draw->setstrokecolor('#4a76bd');
    
// Get the stroke color 
$strokeColor = $draw->getstrokecolor()->getcolor(); 
echo $strokeColor
?> 


Output:

rgb(19018, 30326, 48573)

Used Image:

Program 3:




<?php
  
// Create a new Gmagick object
$gmagick = new Gmagick('neveropen.png');
  
// Create a GmagickDraw object
$draw = new GmagickDraw();
  
// Set the color
$draw->setFillColor('#0E0E0E');
  
// Draw rectangle for background
$draw->rectangle(-10, -10, 800, 400);
  
// Set the fill color
$draw->setFillColor('white');
  
// Set the color of stroke
$draw->setStrokeColor('red');
  
// Set the width of stroke
$draw->setstrokewidth(1);
  
// Set the font size
$draw->setFontSize(20);
  
// Get the stroke color
$strokecolor = $draw->getstrokecolor()->getcolor();
  
// Annotate a text
$draw->annotate(50, 100,
    'The stroke color here is ' . $strokecolor);
  
// Use of drawimage functeannotate
$gmagick->drawImage($draw);
  
// Display the output image
header("Content-Type: image/png");
echo $gmagick->getImageBlob();
?>


Output:

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

RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32520 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6903 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12115 POSTS0 COMMENTS
Shaida Kate Naidoo
7023 POSTS0 COMMENTS
Ted Musemwa
7265 POSTS0 COMMENTS
Thapelo Manthata
6981 POSTS0 COMMENTS
Umr Jansen
6973 POSTS0 COMMENTS