Related Articles

Related Articles

PHP | Imagick setImageAlphaChannel() Function
  • Last Updated : 15 Nov, 2019

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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();
?>

chevron_right


Output:

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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();
?>

chevron_right


Output:

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




My Personal Notes arrow_drop_up
Recommended Articles
Page :