Open In App

PHP | imagesetinterpolation() Function

Improve
Improve
Like Article
Like
Save
Share
Report

The imagesetinterpolation() function is an inbuilt function in PHP which is used to set the interpolation method, setting an interpolation method affects the rendering of various functions such as the imagerotate() function.
Syntax: 
 

bool imagesetinterpolation( resource $image, int $method )

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

  • $image: It specifies the image resource to work on.
  • $method: It specifies the method to apply. 
    The list of methods available are given below: 
    • IMG_BELL: Bell filter.
    • IMG_BESSEL: Bessel filter.
    • IMG_BICUBIC: Bicubic interpolation.
    • IMG_BICUBIC_FIXED: Fixed point implementation of the bicubic interpolation.
    • IMG_BILINEAR_FIXED: Fixed point implementation of the bilinear interpolation (default (also on image creation)).
    • IMG_BLACKMAN: Blackman window function.
    • IMG_BOX: Box blur filter.
    • IMG_BSPLINE: Spline interpolation.
    • IMG_CATMULLROM: Cubic Hermite spline interpolation.
    • IMG_GAUSSIAN: Gaussian function.
    • IMG_GENERALIZED_CUBIC: Generalized cubic spline fractal interpolation.
    • IMG_HERMITE: Hermite interpolation.
    • IMG_HAMMING: Hamming filter.
    • IMG_HANNING: Hanning filter.
    • IMG_MITCHELL: Mitchell filter.
    • IMG_POWER: Power interpolation.
    • IMG_QUADRATIC: Inverse quadratic interpolation.
    • IMG_SINC: Sinc function.
    • IMG_NEAREST_NEIGHBOUR: Nearest neighbour interpolation.
    • IMG_WEIGHTED4: Weighting filter.
    • IMG_TRIANGLE: Triangle interpolation.

Return Value: This function returns TRUE on success or FALSE on failure.
Below examples illustrate the imagesetinterpolation() function in PHP:
Example 1: 
 

php




<?php
 
// Load the png image
$image = imagecreatefrompng(
 
// Set the interpolation
imagesetinterpolation($image, IMG_BLACKMAN);
 
// Rotate the image
$black = imagecolorallocate($image, 0, 0, 0);
$rotated = imagerotate($image, 20, $black);
 
// Output image to the browser
header('Content-type: image/png');
imagepng($rotated);
?>


Output: 
 

Example 2: 
 

php




<?php
 
// Load the png image
$image = imagecreatefrompng(
 
// Set the interpolation
imagesetinterpolation($image, IMG_POWER);
 
// Rotate the image
$black = imagecolorallocate($image, 0, 0, 0);
$rotated = imagerotate($image, 20, $black);
 
// Output image to the browser
header('Content-type: image/png');
imagepng($rotated);
?>


Output: 
 

Reference: https://www.php.net/manual/en/function.imagesetinterpolation.php
 



Last Updated : 13 Jul, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads