Friday, October 24, 2025
HomeLanguagesPHP | imagesetinterpolation() Function

PHP | imagesetinterpolation() Function

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
 

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS