Open In App

PHP | Imagick setImageAlphaChannel() Function

Last Updated : 15 Nov, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

The Imagick::setImageAlphaChannel() function is an inbuilt function in PHP which is used to set the image alpha channel.

Syntax:

bool Imagick::setImageAlphaChannel( int $mode )

Parameters: This function accepts single parameter $mode which holds an integer value corresponding to one of the ALPHACHANNEL constants.

List of ALPHACHANNEL constants are given below:

  • imagick::ALPHACHANNEL_ACTIVATE (0)
  • imagick::ALPHACHANNEL_DEACTIVATE (1)
  • imagick::ALPHACHANNEL_RESET (2)
  • imagick::ALPHACHANNEL_SET (3)
  • imagick::ALPHACHANNEL_UNDEFINED (4)
  • imagick::ALPHACHANNEL_COPY (5)
  • imagick::ALPHACHANNEL_EXTRACT (6)
  • imagick::ALPHACHANNEL_OPAQUE (7)
  • imagick::ALPHACHANNEL_SHAPE (8)
  • imagick::ALPHACHANNEL_TRANSPARENT (9)

Return Value: This function returns TRUE on success.

Below programs illustrate the Imagick::setImageAlphaChannel() function in PHP:

Program 1:




<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
// Set background color
$imagick->setImageBackgroundColor('blue');
  
// Set the ImageAlphaChannel to 9 which corresponds
// to imagick::ALPHACHANNEL_TRANSPARENT
$imagick->setImageAlphaChannel(9);
  
// Display the image
header("Content-Type: image/png");
  
echo $imagick->getImageBlob();
?>


Output:

Program 2:




<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
// Set the ImageAlphaChannel to 3 which corresponds to
// imagick::ALPHACHANNEL_SET
$imagick->setImageAlphaChannel(3);
  
// Display the image
header("Content-Type: image/png");
  
echo $imagick->getImageBlob();
?>


Output:

Reference: https://www.php.net/manual/en/imagick.setimagealphachannel.php



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads