Results 1 to 9 of 9
  1. #1
    Join Date
    Dec 2005
    Posts
    395

    PHP paint bucket

    Does anyone know of a script, which when given a specific pixel of an image, will find all the pixels adjacent to that pixel that have the same color? I am thinking similar to the way a paint bucket works in which it will keep finding pixels with the same value until the surrounding pixels are all different.

  2. #2
    Join Date
    May 2005
    Location
    Planet Earth
    Posts
    813
    Hi,

    using GD you can achieve such thing.

    Try:
    PHP Code:
    $color imagecolorat($image,$x_coord,$y_coord);

    $color_down imagecolorat($image,$x_coord,$y_coord+1);
    $color_up imagecolorat($image,$x_coord,$y_coord-1);
    $color_right imagecolorat($image,$x_coord+1,$y_coord);
    $color_left imagecolorat($image,$x_coord-1,$y_coord);

    // then make some comparison

    // if you want to find all pixel of the same color 'touching' each other
    // implement a recursive function. 
    You should have enough to start coding (or debugging)

    Regards,

    G
    PutFile.io Disrupting traditional file hosting.
    █ Signup Early and enjoy Unlimited space/bandwidth for your files hosting, Forever!
    █ No Ads.
    █ No Countdowns.

  3. #3
    Join Date
    Dec 2005
    Posts
    395
    Yea i tried that, and failed at which point I posted here. Does anyone know of a prewritten script available somewhere?

  4. #4
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  5. #5
    Join Date
    Mar 2006
    Posts
    965
    4images Gallery Script, from 4homepages.de, uses a class function that already pre-sets the width and height size of your image automatically. Once you know how to operate the object name, it's pretty easy to duplicate it's process several times in a row (GD required).

    For the automated image size (width / height) - physically, it's already detecting each images size by using the $width and $height variables. I think this is the solution you're trying to resolve.

    Edit: Foobic's post wasn't there before I posted my solution. Consider using the posted URL, above, before using mine. Use it if it still fails.

  6. #6
    Join Date
    Dec 2005
    Posts
    395
    Thanks for the post guys, exactly what i was looking for

  7. #7
    had same problem, but I need also like Photoshop Tolerance function? Maybe somebody help me?
    HostNodeList Web Host Directory, DEV.INTOEX.COM - products for online business

    Experienced web-developer | PHP | Smarty | Zend | Databases | Graphic design - looking for long-time relationship

  8. #8
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    I don't think the image libraries support that.

    One possible approach:
    1. copy image
    2. on the copy reduce colour depth, flood fill, replace all colours other than the fill colour with transparent
    3. overlay copy on original image

    May give you a similar effect...
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  9. #9
    Join Date
    Dec 2005
    Posts
    395
    *wrong thread*

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •