略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: imagefilltoborder

2024-12-22

imagefilltoborder

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

imagefilltoborder区域填充到指定颜色的边界为止

说明

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

imagefilltoborder()xy(图像左上角为 0, 0)点开始用 color 颜色执行区域填充,直到碰到颜色为 border 的边界为止。【注:边界内的所有颜色都会被填充。如果指定的边界色和该点颜色相同,则没有填充。如果图像中没有该边界色,则整幅图像都会被填充。】

add a noteadd a note

User Contributed Notes 2 notes

up
1
edrad at wanadoo dot fr
19 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
17 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.

官方地址:https://www.php.net/manual/en/function.imagefilltoborder.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3