imagesetinterpolation

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

imagesetinterpolationEstablecer el método de interpolación

Descripción

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

Establece el método de interpolación. Establecer un método de interpolación afecta la renderización de varias funciones de GD, tal como la función imagerotate().

Parámetros

image

Un recurso image, es devuelto por una de las funciones de creación de imágenes, como imagecreatetruecolor().

method

El método de interpolación, que puede ser uno de los siguientes:

Valores devueltos

Devuelve true en caso de éxito o false en caso de error.

Ejemplos

Ejemplo #1 Ejemplo de imagesetinterpolation()

<?php
// Cargar una image
$im = imagecreate(500, 500);

// Por omisión, la interpolación es IMG_BILINEAR_FIXED, se cambia
// para usar el filtro 'Mitchell':
imagesetinterpolation($im, IMG_MITCHELL);

// Continuar trabajando con $im ...
?>

Notas

Cambiar el método de interpolación afecta a las siguientes funciones al renderizar:

add a note add a note

User Contributed Notes 1 note

up
-1
shaun at slickdesign dot com dot au
6 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