Open In App

PHP | Imagick sampleImage() Function

Last Updated : 06 Dec, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

The Imagick::sampleImage() function is an inbuilt function in PHP which is used to scale an image to the desired dimensions with pixel sampling.This method does not introduce any additional color into the scaled image like other resizing methods.

Syntax:

bool Imagick::sampleImage( int $rows, int $columns )

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

  • $rows: It specifies the height.
  • $columns: It specifies the width.

Return Value: This function returns TRUE on success.

Exceptions: This function throws ImagickException on error.

Below given programs illustrate the Imagick::sampleImage() function in PHP:

Program 1:




<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
// Sample the image
$imagick->sampleImage(300, 300);
  
// Display the image
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>


Output:

Program 2:




<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
// Sample the image
$imagick->sampleImage(400, 300);
  
// Display the image
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>


Output:

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



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

Similar Reads