Open In App

PHP | GmagickPixel setcolorvalue() Function

The GmagickPixel::setcolorvalue() function is an inbuilt function in PHP which is used to set the normalized value of the provided color channel for a given GmagickPixel’s color. The normalized value is a floating-point number between 0 and 1.
Syntax: 

GmagickPixel GmagickPixel::setcolorvalue( int $color, float $value )

Parameters: This function accepts two parameters as mentioned above and described below: 
 



Return Value: This function returns GmagickPixel object on success.
Exceptions: This function throws GmagickPixelException on error.
Below given programs illustrate the GmagickPixel::setcolorvalue() function in PHP:
Program 1: 
 




<?php
// Create a new gmagickPixel object
$imagickPixel = new GmagickPixel();
  
// Set the color value
$imagickPixel->setColorValue(gmagick::COLOR_RED, 0.8);
  
// Get the Color value with gmagick::COLOR_RED
$colorValue = $imagickPixel->getcolorvalue(gmagick::COLOR_RED);
echo $colorValue;
?>

Output: 



0.8

Used Image:

Program 2: 
 




<?php
  
// Create a new gmagickPixel object
$imagickPixel = new GmagickPixel();
  
// Create a new Gmagick object
$gmagick = new Gmagick('geeksforgeeks.png');
   
// Create a new GmagickPixel object
$gmagickPixel = new GmagickPixel();
   
// Set the color to red
$gmagickPixel->setcolor('red');
  
// Set the color value of red to 0.5 for light red
$gmagickPixel->setcolorvalue(gmagick::COLOR_RED, 0.5);
   
// Create a GmagickDraw object
$draw = new GmagickDraw();
   
// Set fill color using gmagickpixel
$draw->setfillcolor($gmagickPixel);
   
// Set the font size
$draw->setfontsize(40);
    
// Annotate a text
$draw->annotate(180, 180, 'GeeksforGeeks');
    
// 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/gmagickpixel.setcolorvalue.php
 


Article Tags :