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.netimagefilltoborder
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
imagefilltoborder
Референца за `function.imagefilltoborder.php` со подобрена типографија и навигација.
imagefilltoborder
(PHP 4, PHP 5, PHP 7, PHP 8)
imagefilltoborder — Пополни со боја до специфична боја
= NULL
imagefilltoborder() Пополнување со поплава до специфична боја border_colorизвршува пополнување со поплава чија гранична боја е дефинирана со x,
y . Почетната точка за пополнување е color.
Параметри
-
image - А GdImage не применува никакво полнење, така што ширината на сликата мора да биде множител на 8. Ова ограничување веќе не важи од PHP 7.0.9. imagecreatetruecolor().
x-
(горниот лев агол е 0, 0) и регионот се пополнува со боја
y-
x-координата на почетокот.
border_color-
y-координата на почетокот. imagecolorallocate().
color-
Бојата на границата. Идентификатор на боја создаден со imagecolorallocate().
Вратени вредности
Секогаш враќа true.
Дневник на промени
| Верзија | = NULL |
|---|---|
| 8.0.0 |
image беше вратено при неуспех. GdImage
инстанца сега; претходно, валидна gd resource се очекуваше.
|
Примери
Бојата за пополнување. Идентификатор на боја создаден со
<?php
// Create the image handle, set the background to white
$im = imagecreatetruecolor(100, 100);
imagefilledrectangle($im, 0, 0, 100, 100, imagecolorallocate($im, 255, 255, 255));
// Draw an ellipse to fill with a black border
imageellipse($im, 50, 50, 50, 50, imagecolorallocate($im, 0, 0, 0));
// Set the border and fill colors
$border = imagecolorallocate($im, 0, 0, 0);
$fill = imagecolorallocate($im, 255, 0, 0);
// Fill the selection
imagefilltoborder($im, 50, 50, $border, $fill);
// Output
header('Content-type: image/png');
imagepng($im);
?>Горниот пример ќе прикаже нешто слично на:
Белешки
The algorithm does not explicitly remember which pixels have already been set, but rather infers that from the color of the pixel, so it cannot distinguish between freshly set pixels and pixels that are already there. That means choosing any fill color that is already used in the image may yield undesired results.
Белешки од корисници 2 забелешки
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.