設定內插法並不會套用到 imageaffine() 或 imagerotate() 建立的任何影像。它預設為 IMG_BILINEAR_FIXED,需要根據需要在每個生成的影像上設定。
<?php
imagesetinterpolation( $image, IMG_NEAREST_NEIGHBOUR );
// 使用 IMG_NEAREST_NEIGHBOUR 旋轉
$rotated = imagerotate( $image, 45, $transparent );
// 使用 IMG_BILINEAR_FIXED 旋轉
$rotated_again = imagerotate( $rotated, 45, $transparent );
?>
將內插法設定為 IMG_NEAREST_NEIGHBOUR 有助於在以 90 度增量旋轉影像時保留細節並防止取樣問題,包括順時針旋轉時。
<?php
// 旋轉後的影像可能看起來模糊且略微傾斜。
$rotated = imagerotate( $image, -360, $transparent );
// 與原始影像相似,但仍可能顯示背景或略微傾斜。
imagesetinterpolation( $image, IMG_NEAREST_NEIGHBOUR );
$rotated = imagerotate( $image, -360, $transparent );
?>