Portrety Uliczne Nieznajomych - zobacz wyjątkową galerię portretów z warszawskich ulic
ZALOGUJ SIĘ
login:
hasło:
przypomnij hasło
załóż konto użytkownika
(i zobacz kilka porad gratis)
   
WYSZUKIWARKA I DZIAŁY
całe porady  tytuły
zaznacz działy do przeszukania
(brak wyboru = wszystkie działy)
PHP
MySQL >
PostgreSQL
SQLite
Perl
Java
XML
XSLT
XPath
WML
SVG
RegExp
Wyszukiwarki
Ochrona
VBScript
Google Plus
XHTML/CSS
JavaScript
Grafika
Flash
Photoshop
Windows
Linux
Bash
Apache
Procmail
E-biznes
Explorer
Opera
Firefox
Inne porady
   
KURSY, DOKUMENTACJE
Własne:
XHTML/CSS
JavaScript
ActionScript
WML, RSS, SSI
Pozostałe:
PHP
MySQL
Java API
więcej...
   
użytkowników online: 40
W CZYM MOGĘ POMÓC?


   
OPINIE UŻYTKOWNIKÓW
Nie jestem webmasterem, ale i na mnie zrobiła wrażenie szybkość reakcji Darka na mój problem. Jego kompetencja i przede wszystkim zupełnie niemodna w dzisiejszych skomercjalizowanych czasach - zwykła ludzka życzliwość dla innego człowieka. Tacy ludzie to dziś gatunek niemal wymarły...

Leszek
Wojskowy Instytut Medyczny

   
GALERIA FOTOGRAFII
   
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net

[Spis] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [X] [W] [Z]

imagefilltoborder

(PHP 3, PHP 4, PHP 5)

imagefilltoborder -- Flood fill to specific color

Description

int imagefilltoborder ( resource image, int x, int y, int border, int color )

imagefilltoborder() performs a flood fill whose border color is defined by border. The starting point for the fill is x, y (top left is 0, 0) and the region is filled with color color.




User Contributed Notes

php at corzoogle dot com
27-Jun-2005 09:08

pritm (.a.t.) mail (.d.0.t.) ru, your jpg black areas aren't entirely black, look *real* closely at it! so the fill will "seep through". the solution is simple, use a lossless background image format. replace this line..

<?
$im
= imagecreatefrompng ('map-back.png');
?>

try it with this version of your image..

http://corz.org/public/images/demo/map-back.png
(the colours may be slightly different, just a quick conversion in my regular image viewer)

as you can see, it works perfectly..
http://corz.org/public/images/demo/filled.jpg

;o)
(or


Henrik Nyh
24-Jun-2005 10:26

Reply to pritm (.a.t.) mail (.d.0.t.) ru below.

I had a similar problem and solved it thus:

I had to reduce the number of colors on the image I was using. It appeared to be a black and white map, but contained about 50 shades of almost black and almost white. I reduced this to two colors only (also going from JPG to GIF) so that the borders as well as the areas to be filled each were of a consistent shade.

Additionally, it did not work when I specified border colors as black (0,0,0), even though they seem to be of this exact shade in the map file. Instead, I used ImageColorAt() to pick the border color, and now everything seems to work.

Image: http://henrik.nyh.se/dump/map/europe.gif
In action: http://henrik.nyh.se/dump/map/map.html

Source:

<?php

$map
= "europe.gif";

$img = ImageCreateFromGIF($map);

// Colors
$border = ImageColorAt ($img, 416, 111);  // Get color of borders - apparently (0,0,0) won't work
$red = ImageColorAllocate($img, 255, 0, 0);
$green = ImageColorAllocate($img, 0, 255, 0);

// Fill
ImageFillToBorder($img, 440, 100, $border, $red);  // Sweden
ImageFillToBorder($img, 250, 290, $border, $green);  // Great Britain

// Output image as PNG
header("Content-type: image/png");
ImagePNG($img);
ImageDestroy($img);  // Free memoryu

?>


pritm (.a.t.) mail (.d.0.t.) ru
22-May-2005 10:53

Has found a problem from which I can not consult. Please help.

For example a code such:

$im = imagecreatefromjpeg ('map-back.jpg');
$marker = ImageColorAllocate ($im, 0, 0, 160);

// Colors [black] and [col] are identical.
// Of what it is possible to be convinced having changed these values
$black = ImageColorAllocate ($im, 0, 0, 0);
$col = ImageColorAt ($im, 49, 297);

// The rectangular is well led round during processing
ImageRectangle ($im, 20, 20, 50, 50, $col);
// For check of taken color (should be black)
imageLine ($im, 25,25,45,45, $col);

//Fill
ImageFillToBorder ($im, 160,300, $col, $marker);

// A conclusion
imagejpeg ($im, '', 100);
ImageDestroy ($im);

In result all is filled in jpg (except for a rectangular and parts of border) though the point fill undertook inside a figure with black border. And the normal result should be only a filled figure.

Look as:
Primary picture
http://nugna.info/map-back.jpg

As a result of performance of a script:
http://nugna.info/is-now.jpg

It is necessary to receive:
http://nugna.info/need.jpg

How it to achieve?


pritm (.a.t.) mail (.d.0.t.) ru
22-May-2005 10:49

Has found a problem from which I can not consult. Please help.

For example a code such:

$im = imagecreatefromjpeg ('map-back.jpg');
$marker = ImageColorAllocate ($im, 0, 0, 160);

// Colors [black] and [col] are identical.
// Of what it is possible to be convinced having changed these values
$black = ImageColorAllocate ($im, 0, 0, 0);
$col = ImageColorAt ($im, 49, 297);

// The rectangular is well led round during processing
ImageRectangle ($im, 20, 20, 50, 50, $col);
// For check of taken color (should be black)
imageLine ($im, 25,25,45,45, $col);

//Fill
ImageFillToBorder ($im, 160,300, $col, $marker);

// A conclusion
imagejpeg ($im, '', 100);
ImageDestroy ($im);

In result all is filled in jpg (except for a rectangular and parts of border) though the point fill undertook inside a figure with black border. And the normal result should be only a filled figure.

Look as:
Primary picture
http://nugna.info/map-back.jpg

As a result of performance of a script:
http://nugna.info/is-now.jpg

It is necessary to receive:
http://nugna.info/need.jpg

How it to achieve?


sbuchanan at datadiver dot net
11-May-2005 12:08

edrad's pseudo-sphere is pretty nice, but a few tweeks really improve it.  (writing out the image header so a browser actually understands it and calling imagedestroy() so we clean up memory are nice things to do, too).  Try drawing it at twice the size and then resampling it down.  Takes more CPU, but it forces antialiasing, creating a smooth arc.  Also, render it at diameter = (width - 1) * 2.  Taking one pixel off the outside keeps it off the image edge, eliminating those ugly flat spots.  Render it on white first so you can really see the edge, then switch back to the cool grey...

Oh, and use imagecreatetruecolor instead of imagecreate if you have it available.

I agree that imageellipse is easier, though.  Actually, I generate rounded corners with drop-shadows for CSS with imagefilledarc (kind of a blend of the two)  Use imagefilledellipse if drawing the whole thing, use imagefilledarc if only drawing part of it (like a corner).  If you use the 'filled' functions you can skip imagefilltoborder altogether :P

Anyway, try this for a smoother image:

<?php

  $requested_width
= 300;
 
$render_width = ($requested_width * 2) - 1; // -1 to back away from edge, removing flat spot
 
$center = $render_width / 2
 
$colordivs = 255 / $center;
 
$im_scratch = @imagecreate($render_width, $render_width);

 
//$back_color = imagecolorallocate($im_scratch, 20, 30, 40);  // try it with white so you can really see the edge first..
 
$back_color = imagecolorallocate($im_scratch, 255, 255, 255);

 
imagefill($im_scratch, 0, 0, $back_color);

  for (
$i = 0; $i <= $center; $i++) {
  
$diametre = $render_width - 2 * $i;
  
$el_color = imagecolorallocate($im_scratch, $i * $colordivs, 0, 0);
  
imageellipse($im_scratch, $center, $center, $diametre, $diametre, $el_color);
  
imagefilltoborder($im_scratch, $center, $center, $el_color, $el_color);
  }

 
// resample down, causes antialiasing, nice smooth curve!
 
$im = @imagecreatetruecolor($requested_width, $requested_width);
 
imagecopyresampled($im, $im_scratch, 0, 0, 0, 0, $requested_width, $requested_width, $render_width, $render_width);

 
header ("Content-type: image/png");
 
imagepng($im);
 
ImageDestroy($im);
 
ImageDestroy($im_scratch);

?>


admin at worldlanguages dot tk
10-Sep-2004 11:54

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.


edrad at wanadoo dot fr
11-Jun-2003 02:02

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


ecofarm at mullum dot com dot au
25-Jan-2001 07:18

Great for getting that rounded button look we see a lot of at php.net ... try this sample. (remember to change png to whatever image format your version of php supports)

<?php

   Header
("Content-type: image/png");


    
///// create canvas  /////

  
$im = ImageCreate (80, 25);

 
//define colors.. first color declared is set as background

  
$blue  = ImageColorAllocate ($im, 0, 0, 255);
  
$white  = ImageColorAllocate ($im, 255, 255, 255);

    
// draw semi-circle arcs at each end

  
ImageArc($im, 12, 12, 23, 26, 90, 270, $white);
  
ImageArc($im, 67, 12, 23, 26, 270, 90, $white);

    
// fill ends outside arcs with color

  
ImageFillToBorder ($im, 0, 0, $white, $white);
  
ImageFillToBorder ($im, 79, 0, $white, $white);

    
// create the image

  
ImagePng ($im);

    
// destroy the image to free memory

  
ImageDestroy ($im);
?>


 

 
  © 1996-2012 & Reporter.plmiejscao serwisieabonamentwarunki korzystaniaRSSkontakt