PHP | GmagickPixel __construct() Function

The GmagickPixel::__construct() function is an inbuilt function in PHP which is used to construct an GmagickPixel object. If a color is specified, the object is constructed and then initialized with that color before being returned.

Syntax:

GmagickPixel GmagickPixel::__construct( string $color )

Parameters: This function accepts a single parameter $color which is optional and holds the color.

Return Value: This function returns GmagickPixel object on success.

Exceptions: This function throws GmagickPixelException on error.



Below given programs illustrate the GmagickPixel::__construct() function in PHP:

Program 1 (Without color parameter):

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new GmagickPixel
// object using __construct
$gmagickPixel = new GmagickPixel();
  
// Get the color
$color = $gmagickPixel->getcolor();
echo $color;
?>

chevron_right


Output:

rgb(0, 0, 0)

Program 2 (With color parameter):

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new GmagickPixel object
// using __construct
$gmagickPixel = new GmagickPixel('#ccb062');
  
// Get the color
$color = $gmagickPixel->getcolor();
echo $color;
?>

chevron_right


Output:

rgb(52428, 45232, 25186)

Reference: https://www.php.net/manual/en/gmagickpixel.construct.php

My Personal Notes arrow_drop_up

I love Open Source Culture have contributed to phpMyAdmin, LibreOffice, Ant-Design and Web is my passion

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.