imagefill 


gd apg

PERFORMS a flood fill starting at the given coordinate.





$x = 0 and $y = 0 are the coordinates of the top left point.

This function returns TRUE on success or FALSE on failure.



<?php

bool imagefill 
GdImage $imageint $xint $yint $color )


where,

$image The image identifier 

$x 
The x-coordinate of the start point 

$y 
The y-coordinate of the start point 

$color 
The fill color as returned by imagecolorallocate

?>
 

  $image   


The image identifier.



  $x   


x-coordinate of start point.



  $y   


y-coordinate of start point.



  $color   


The fill color, a color identifier created by imagecolorallocate.



  1 EXERCISE   

<?php

echo 'PHP VERSION: ' PHP_VERSION '<br><br>'

$file01 'png/PNG 067 01 imagefill.png'

$id_01 imagecreatetruecolor(30080); 
$color01 imagecolorallocate($id_0102550); 

$xf01 20;

$yf01 20;

imagefill($id_01$xf01$yf01$color01);
    
imagepng($id_01$file01); 

imagedestroy($id_01); 

echo 
$file01?><br><br><img src="<?php echo $file01?>
 alt="<?php echo $file01?>" title="<?php echo $file01?>"><br>

 

 RESULT   

PNG 067 01 imagefill.png

PNG 067 01 imagefill.png apr

Although the image was created by the imagecreatetrucolor function ,(black background by default), the image was filled with green, the color used by the imagefill function.

  2 EXERCISE   

<?php

echo 'PHP VERSION: ' PHP_VERSION '<br><br>'

$file02 'png/PNG 067 02 imagefill.png';  

$id_02 imagecreate(30080);

$red02 mt_rand(0255);

$green02 mt_rand(0255);

$blue02 mt_rand(0255);

$color02 
imagecolorallocate($id_02$red02$green02$blue02); 

$xf02 0;

$yf02 0;

imagefill($id_02$xf02$yf02$color02);
    
imagepng($id_02$file02); 

imagedestroy($id_02); 

echo 
$file02?><br><br> <img src="<?php echo $file02?>
 alt="<?php echo $file02?>" title="<?php echo $file02?>"><br> 
 
 

 RESULT   

PNG 067 02 imagefill.png

PNG 067 02 imagefill.png apr

Although the image was created by the imagecreate function (has the first color defined by imagecolorallocate as its background color, the background color has been redefined by imagefill function at each new run.

So this is a particular result.

You must test several times.


  3 EXERCISE   

<?php

echo 'PHP VERSION: ' PHP_VERSION '<br><br>'

$file03 'jpeg/JPEG 030 03 imagefill.jpg';

$q03 50;

$id_03 imagecreate(200,200);
$clr_1_03 imagecolorallocate($id_032552550);
$clr_2_03 imagecolorallocate($id_0300250);
$clr_4_03 imagecolorallocate($id_032,2,55);
imagerectangle($id_03100100150150$clr_4_03);
imagefill($id_03110110$clr_2_03);

imagejpeg ($id_03$file03 $q03);

echo 
$file03 '<br><br>'?> <img src="<?php echo $file03?>"  
 alt="<?php echo $file03?>" title="<?php echo $file03?>">
 
 

 RESULT   

JPEG 030 03 imagefill.jpg

JPEG 030 03 imagefill.jpg apr

  4 EXERCISE   

<?php

echo 'PHP VERSION: ' PHP_VERSION '<br><br>'

$file04 'png/PNG 067 04 imagefill.png'

$q04 5

$f04 PNG_ALL_FILTERS;

$id_04 imagecreatetruecolor(200,200);
$clr_1_04 imagecolorallocate($id_042552550);
$clr_2_04 imagecolorallocate($id_0400250);
$clr_4_04 imagecolorallocate($id_042,2,55);

imagefill($id_0400$clr_1_04);

imagerectangle($id_04100100150150$clr_4_04);
imagefill($id_041010$clr_2_04);
imagepng ($id_04$file04$q04$f04 );
imagedestroy($id_04);

echo 
$file04?><br><br><img src="<?php echo $file04?>"  
 alt="<?php echo $file04?>" title="<?php echo $file04?>"> 

 RESULT   

PNG 067 04 imagefill.png

PNG 067 04 imagefill.png apr

  5 EXERCISE   

<?php

echo 'PHP VERSION: ' PHP_VERSION '<br><br>'

$base_img "png/baseXx.png";

$dest_img "png/PNG 067 05 imagefill.png";

$quality 9;

$filter 4
// PNG_FILTER_PAETH

echo basename($base_img) . '<br><br>'?>
<img src="<?php echo $base_img?>
alt="<?php echo $base_img?>"><br><br><br>

<?php

$id_polig 
imagecreatefrompng$base_img);

$colorln imagecolorallocate($id_polig25500);

$colorfl imagecolorallocate($id_polig02550);

imagefill($id_polig110162$colorfl);

imagefill($id_polig162152$colorfl);

imagefill($id_polig200170$colorfl);

imagefill($id_polig223164$colorfl);

imagepng($id_polig,  $dest_img$quality$filter);

echo 
basename($dest_img) . '<br><br>Resulting Image'?>
<br><br><img src="<?php echo $dest_img?>
alt="<?php echo $dest_img?>"> 

 RESULT   

baseXx.png

baseXx.png apr


PNG 067 05 imagefill.png

Resulting Image

PNG 067 05 imagefill.png apr