imagesetinterpolation

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

imagesetinterpolationDefine el método de interpolación

Descripción

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

Define el método de interpolación; el hecho de definir un método de interpolación afecta el rendimiento de varias funciones en GD, como por ejemplo la función imagerotate().

Parámetros

image

Un objeto GdImage, retornado 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

Esta función retorna true en caso de éxito o false si ocurre un error.

Historial de cambios

Versión Descripción
8.0.0 image expects a GdImage instance now; previously, a valid gd resource was expected.

Ejemplos

Ejemplo #1 Ejemplo con imagesetinterpolation()

<?php
// Carga de la imagen
$im = imagecreate(500, 500);

// Por defecto, la interpolación es IMG_BILINEAR_FIXED; se utiliza en su lugar
// el filtro 'Mitchell':
imagesetinterpolation($im, IMG_MITCHELL);

// Se continúa trabajando con $im...
?>

Notas

La modificación del método de interpolación afecta a las siguientes funciones durante el rendimiento:

Ver también

add a note

User Contributed Notes 1 note

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