imagesetinterpolation 


gd apg

SETS the interpolation method, setting an interpolation method affects the rendering of various functions in GD, such as the imagerotate function.

The imagerotate function has already been seen on the previous page.





This function returns TRUE on success or FALSE on failure.



<?php

bool imagesetinterpolation
GdImage $image
                                                       
int $method IMG_BILINEAR_FIXED )

where,

$image The image identifier

$method 
The interpolation method
                 
SEE the below TABLE )

?>

  $image   


The image identifier.



  $method   


The interpolation method:

IMAGE INTERPOLATION CONSTANTS
CONSTANT VALUE MEANING
IMG_BELL 1 Bell filter
IMG_BESSEL 2 Bessel filter
IMG_BILINEAR_FIXED 3 Fixed point implementation of the bilinear interpolation
IMG_BICUBIC 4 Bicubic interpolation
IMG_BICUBIC_FIXED 5 Fixed point implementation of the bicubic interpolation
IMG_BLACKMAN 6 Blackman window function
IMG_BOX 7 Box blur filter
IMG_BSPLINE 8 Spline interpolation
IMG_CATMULLROM 9 Cubic Hermite spline interpolation
IMG_GAUSSIAN 10 Gaussian function
IMG_GENERALIZED_CUBIC 11 Generalized cubic spline fractal interpolation
IMG_HERMITE 12 Hermite interpolation
IMG_HAMMING 13 Hamming filter
IMG_HANNING 14 Hanning filter
IMG_MITCHELL 15 Mitchell filter
IMG_NEAREST_NEIGHBOUR 16 Nearest neighbour interpolation
IMG_POWER 17 Power interpolation
IMG_QUADRATIC 18 Inverse quadratic interpolation
IMG_SINC 19 Sinc function
IMG_TRIANGLE 20 Triangle interpolation
IMG_WEIGHTED4 21 Weighting filter
ed48


  1 EXERCISE   

<?php

echo 'PHP VERSION: ' PHP_VERSION '<br><br>';

$image01 'gif/GIF 028 01.gif';
// Ocaporã - PALETTE IMAGE

$intrp01 = [ 
"IMG_BELL" => IMG_BELL,
"IMG_BESSEL" => IMG_BESSEL,
"IMG_BILINEAR_FIXED" => IMG_BILINEAR_FIXED,
"IMG_BICUBIC" => IMG_BICUBIC
"IMG_BICUBIC_FIXED" => IMG_BICUBIC_FIXED
"IMG_BLACKMAN" => IMG_BLACKMAN,
"IMG_BOX" => IMG_BOX
"IMG_BSPLINE" => IMG_BSPLINE
"IMG_CATMULLROM" => IMG_CATMULLROM,
"IMG_GAUSSIAN" => IMG_GAUSSIAN
"IMG_GENERALIZED_CUBIC" => IMG_GENERALIZED_CUBIC,
"IMG_HERMITE" => IMG_HERMITE
"IMG_HAMMING" => IMG_HAMMING
"IMG_HANNING" => IMG_HANNING
"IMG_MITCHELL" => IMG_MITCHELL,
"IMG_NEAREST_NEIGHBOUR" => IMG_NEAREST_NEIGHBOUR
"IMG_POWER" => IMG_POWER
"IMG_QUADRATIC" => IMG_QUADRATIC
"IMG_SINC" => IMG_SINC
"IMG_TRIANGLE" => IMG_TRIANGLE,
"IMG_WEIGHTED4" => IMG_WEIGHTED4 
];

echo 
$image01 '<br><br>Existing Image</span>'?><br><br>
<img src="<?php echo $image01?>"
alt="<?php echo $image01?>
title="<?php echo $image01?>"><br><br> 

<?php

$id_img01 
imagecreatefromgif($image01);

$bkg_01 0xeeeeee;

foreach(
$intrp01 as $method01 => $meth01 )
{

$int_image01 'gif/GIF 028 01-' $method01 '.gif';

$b01 imagesetinterpolation($id_img01$meth01);

imagegif($id_img01$int_image01);

echo 
'<br><br>' basename($int_image01) . '<br><br>
Filter: ' 
$method01 '<br>';

?>

<img src="<?php echo $int_image01?>"
alt="<?php echo $int_image01?>
title="<?php echo $int_image01?>"><br><br>

<?php 
if(PHP_MAJOR_VERSION >= 8)
{
echo 
$method01 ' = ' imagegetinterpolation($id_img01); 
echo 
'<br><br>';  
}
?>
<?php
}

?>


 RESULT   

GIF 028 01.gif

Existing Image

GIF 028 01.gif apr

Try it for yourself.

  2 EXERCISE   

<?php

echo 'PHP VERSION: ' PHP_VERSION '<br><br>';

$tst_img "gif/GIF 021 02.gif";
// April 25th bridge(POR) - PALETTE IMAGE

$id_org imagecreatefromgif($tst_img);

$intrp = [ IMG_BELLIMG_BESSELIMG_BICUBIC
IMG_BICUBIC_FIXEDIMG_BILINEAR_FIXED
IMG_BLACKMANIMG_BOXIMG_BSPLINE
IMG_CATMULLROMIMG_GAUSSIAN
IMG_GENERALIZED_CUBICIMG_HERMITE
IMG_HAMMINGIMG_HANNINGIMG_MITCHELL
IMG_POWERIMG_QUADRATICIMG_SINC
IMG_NEAREST_NEIGHBOURIMG_WEIGHTED4
IMG_TRIANGLE ];

$intrs = [ "BELL""BESSEL""BICUBIC"
"BICUBIC_FIXED""BILINEAR_FIXED"
"BLACKMAN""BOX""BSPLINE"
"CATMULLROM""GAUSSIAN"
"GENERALIZED_CUBIC""HERMITE"
"HAMMING""HANNING""MITCHELL"
"POWER""QUADRATIC""SINC"
"NEAREST_NEIGHBOUR""WEIGHTED4"
"TRIANGLE" ];  

echo 
$tst_img?>
<br><br><img src="<?php echo $tst_img?>
alt="<?php echo $tst_img?>" width="400"><br><br><br><br>

<?php

$ang_r2 
mt_rand(-3030); 
// rotation angle in the numeric range [-30, 30}
$bkg_2 0xeeeeee
// background color
$trn 1;

$rnd_intrp mt_rand(020);
{
imagesetinterpolation($id_org$intrp[$rnd_intrp]);

$id_dst2 imagerotate($id_org$ang_r2$bkg_2$trn );

$dst2_img 'gif/GIF 021 02-' $intrs[$rnd_intrp] . '.gif';

imagegif ($id_dst2$dst2_img);

}

echo 
basename($dst2_img) . '<br><br>
Rotation angle: ' 
$ang_r2 '°'?>
<br><br><img src="<?php echo $dst2_img?>
alt="<?php echo $dst2_img?>" width="400">


 RESULT   

GIF 021 02.gif

Existing Image

GIF 021 02.gif apr

With each new run, a new result will be obtained.

Try it for yourself.



  3 EXERCISE   

<?php

echo 'PHP VERSION: ' PHP_VERSION '<br><br>';

$tst_img "bmp/BMP 008 01.bmp";
// TRUECOLOR IMAGE

$id_org imagecreatefrombmp($tst_img);

$intrp = [ IMG_BELLIMG_BESSELIMG_BICUBIC
IMG_BICUBIC_FIXEDIMG_BILINEAR_FIXED
IMG_BLACKMANIMG_BOXIMG_BSPLINE
IMG_CATMULLROMIMG_GAUSSIAN
IMG_GENERALIZED_CUBICIMG_HERMITE
IMG_HAMMINGIMG_HANNINGIMG_MITCHELL
IMG_POWERIMG_QUADRATICIMG_SINC
IMG_NEAREST_NEIGHBOURIMG_WEIGHTED4
IMG_TRIANGLE ];

$intrs = [ "BELL""BESSEL""BICUBIC"
"BICUBIC_FIXED""BILINEAR_FIXED"
"BLACKMAN""BOX""BSPLINE"
"CATMULLROM""GAUSSIAN"
"GENERALIZED_CUBIC""HERMITE"
"HAMMING""HANNING""MITCHELL"
"POWER""QUADRATIC""SINC"
"NEAREST_NEIGHBOUR""WEIGHTED4"
"TRIANGLE" ];  

echo 
$tst_img?>
<br><br><img src="<?php echo $tst_img?>
alt="<?php echo $tst_img?>"><br><br><br><br>

<?php

$ang_r3 
mt_rand(-3030); 
// rotation angle in the numeric range [-30, 30}
$bkg_3 0xeeeeee
// background color
$trn 1;

$rnd_intrp mt_rand(020);
{
imagesetinterpolation($id_org$intrp[$rnd_intrp]);

$id_dst3 imagerotate($id_org$ang_r3$bkg_3$trn );

$dst3_img 'bmp/BMP 008 01.bmp-' $intrs[$rnd_intrp] . '.bmp';

imagebmp ($id_dst3$dst3_img);

}

echo 
basename($dst3_img) . '<br><br>
Rotation angle: ' 
$ang_r3 '°'?>
<br><br><img src="<?php echo $dst3_img?>
alt="<?php echo $dst3_img?>">


 RESULT   

BMP 008 01.bmp

Existing Image

BMP 008 01.bmp apr

With each new run, a new result will be obtained.

Try it for yourself.