Skip to content
Related Articles

Related Articles

Improve Article

PHP | Imagick setImageVirtualPixelMethod() Function

  • Last Updated : 28 Nov, 2019

The Imagick::setImageVirtualPixelMethod() function is an inbuilt function in PHP which is used to set the image virtual pixel method.

Syntax:

bool Imagick::setImageVirtualPixelMethod( int $method )

Parameters:This function accepts a single parameter $method which contains an integer value corresponding to one of the VIRTUALPIXELMETHOD constants. We can also pass the constant directly like setImageVirtualPixelMethod(imagick::VIRTUALPIXELMETHOD_BLACK);.

All VIRTUALPIXELMETHOD constants are given below:

  • imagick::VIRTUALPIXELMETHOD_UNDEFINED (0)
  • imagick::VIRTUALPIXELMETHOD_BACKGROUND (1)
  • imagick::VIRTUALPIXELMETHOD_CONSTANT (2)
  • imagick::VIRTUALPIXELMETHOD_EDGE (4)
  • imagick::VIRTUALPIXELMETHOD_MIRROR (5)
  • imagick::VIRTUALPIXELMETHOD_TILE (7)
  • imagick::VIRTUALPIXELMETHOD_TRANSPARENT (8)
  • imagick::VIRTUALPIXELMETHOD_MASK (9)
  • imagick::VIRTUALPIXELMETHOD_BLACK (10)
  • imagick::VIRTUALPIXELMETHOD_GRAY (11)
  • imagick::VIRTUALPIXELMETHOD_WHITE (12)
  • imagick::VIRTUALPIXELMETHOD_HORIZONTALTILE (13)
  • imagick::VIRTUALPIXELMETHOD_VERTICALTILE (14)

Return Value: This function returns TRUE on success.



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

Program 1:




<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
// Set the Virtual Pixel Method
$imagick->setImageVirtualPixelMethod(imagick::VIRTUALPIXELMETHOD_BLACK);
  
// Get the Virtual Pixel Method
$virtualPixelMethod = $imagick->getImageVirtualPixelMethod();
echo $virtualPixelMethod;
?>

Output:

 10 // Which corresponds to imagick::VIRTUALPIXELMETHOD_BLACK.

Program 2:




<?php
  
// Create a new Imagick object
$imagick = new Imagick(
  
// Set the Virtual Pixel Method
$imagick->setImageVirtualPixelMethod(imagick::VIRTUALPIXELMETHOD_TILE);
  
// Get the Virtual Pixel Method
$virtualPixelMethod = $imagick->getImageVirtualPixelMethod();
echo $virtualPixelMethod;
?>

Output:

 7 // Which corresponds to imagick::VIRTUALPIXELMETHOD_TILE.

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




My Personal Notes arrow_drop_up
Recommended Articles
Page :