imagefilltoborder

(PHP 4, PHP 5, PHP 7, PHP 8)

imagefilltoborderRellenar con un color específico

Descripción

imagefilltoborder(
    resource $image,
    int $x,
    int $y,
    int $border,
    int $color
): bool

imagefilltoborder() realiza un relleno cuyo color de borde está definido por border. El punto de inicio para el relleno es x, y (superior izquierda es 0, 0) y la region es rellenada con el color color.

Parámetros

image

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

x

Coordenada x del inicio.

y

Coordenada y del inicio.

border

El color del borde. Un identificador de color creado con imagecolorallocate().

color

El color del relleno. Un identificador de color creado con imagecolorallocate().

Valores devueltos

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

Ejemplos

Ejemplo #1 Rellenar una elipse con un color

<?php
// Crear el gestor de imagen, establecer el fondo a blanco
$im = imagecreatetruecolor(100, 100);
imagefilledrectangle($im, 0, 0, 100, 100, imagecolorallocate($im, 255, 255, 255));

// Dibujar una elipse a rellenar con un borde negro
imageellipse($im, 50, 50, 50, 50, imagecolorallocate($im, 0, 0, 0));

// Establecer los colores del borde y del relleno
$borde = imagecolorallocate($im, 0, 0, 0);
$relleno = imagecolorallocate($im, 255, 0, 0);

// Rellenar la selección
imagefilltoborder($im, 50, 50, $borde, $relleno);

// Imprimir y liberar memoria
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>

El resultado del ejemplo sería algo similar a:

Salida del ejemplo : Rellenar una elipse con un color

add a note add a note

User Contributed Notes 2 notes

up
1
edrad at wanadoo dot fr
20 years ago
Very useful to build a pseudo-sphere with a color gradient...

<?php
$width
= 300;
$center = $width / 2;
$colordivs = 255 / $center;
$im = @imagecreate($width, $width);
$back_color = imagecolorallocate($im, 20, 30, 40);
imagefill($im, 0, 0, $back_color);
for (
$i = 0; $i <= $center; $i++)
{
    
$diametre = $width - 2 * $i;
   
$el_color = imagecolorallocate($im, $i * $colordivs, 0, 0);
   
imagearc($im, $center, $center, $diametre, $diametre, 0, 360, $el_color);
   
imagefilltoborder($im, $center, $center, $el_color, $el_color);
}
imagepng($im);
?>

Dark Skull Software
http://www.darkskull.net
up
0
admin at worldlanguages dot tk
19 years ago
In the example below, for those with newer GD versions, it makes more sense to replace:

imagearc($im, $center, $center, $diametre, $diametre, 0, 360, $el_color);

with:

imageellipse($im, $center, $center, $diametre, $diametre, $el_color);

This is obviously simpler.
To Top