Open In App

PHP | Imagick setImageVirtualPixelMethod() Function

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:



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


Article Tags :