imagesetinterpolation

(PHP 5 >= 5.5.0, PHP 7, PHP 8)

imagesetinterpolation — 補間方法を設定する

説明

function imagesetinterpolation(GdImage $image, int $method = IMG_BILINEAR_FIXED): bool

補間方法を設定します。これは、imagerotate() など GD のさまざまな関数のレンダリングに影響を及ぼします。

パラメータ

image
imagecreatetruecolor()のような画像作成関数が返す GdImage オブジェクト。
method

補間方法。次のいずれかで指定します。

戻り値

成功した場合に true を、失敗した場合に false を返します。

変更履歴

バージョン 説明
8.0.0 image は、 GdImage クラスのインスタンスを期待するようになりました。 これより前のバージョンでは、有効な gd resource が期待されていました。

例

例1 imagesetinterpolation() の例

<?php
// 画像を読み込みます
$im = imagecreate(500, 500);

// デフォルトの補間方法は IMG_BILINEAR_FIXED ですが、これを
// 'Mitchell' フィルターに変更します
imagesetinterpolation($im, IMG_MITCHELL);

// $im の作業を続けます
?>

注意

補間方法を変更すると、これらの関数のレンダリングに影響を及ぼします。

参考

+add a note

User Contributed Notes 1 note

up
-1
shaun at slickdesign dot com dot au
8 years ago
Setting the interpolation does not carry through to any images created by imageaffine() or imagerotate(). It defaults to IMG_BILINEAR_FIXED and would need to be set on each generated image as required.

<?php
imagesetinterpolation( $image, IMG_NEAREST_NEIGHBOUR );

// Rotated using IMG_NEAREST_NEIGHBOUR
$rotated = imagerotate( $image, 45, $transparent );

// Rotated using IMG_BILINEAR_FIXED
$rotated_again = imagerotate( $rotated, 45, $transparent );
?>

Setting the interpolation to IMG_NEAREST_NEIGHBOUR can help to preserve details and prevent sampling issues when rotating an image at 90 degree increments, including when rotating clockwise.

<?php
// Rotated image can appear blurred and on a slight angle.
$rotated = imagerotate( $image, -360, $transparent );

// Similar to starting Image although it may still show a background or be on a slight angle.
imagesetinterpolation( $image, IMG_NEAREST_NEIGHBOUR );
$rotated = imagerotate( $image, -360, $transparent );
?>
To Top