Change language

PHP Imagick floodFillPaintImage () function

Note.This method replaces the deprecated Imagick::paintFloodFillImage() function and is available if Imagick was compiled with ImageMagick version 6.3.8 or higher.Syntax:
bool Imagick::floodFillPaintImage (mixed $fill, float $fuzz, mixed $target, int $x, int $y, bool $invert [, int $channel = Imagick::CHANNEL_DEFAULT])
Parameters: Thefunction has seven parameters, as we can see from the syntax above. They are:
  • fill (mixed type) : this parameter is an ImagickPixel object or a string containing the fill color - the color to fill with the pixel (s) with this function.
  • fuzz : This parameter determines the number of fuzz. The blur value is based on the intensity of the colors in the image.
  • target (mixed type) : This parameter is an ImagickPixel object or a string containing the target color to paint.
  • x (Int type) : This parameter sets the starting X-coordinate of the fill.
  • y (Int type) : This parameter sets the starting Y-coordinate fills.
  • invert (mixed type) : if true, draws any pixel that does not match the target color. In short, it works the other way around (hence inverts) to fill the remaining pixels separately from the target color. If we only want the target color to be filled, then we would set it to FALSE by default.
  • channel (Int type) : This parameter is used to provide any channel constant, which is valid according to our requirement. If the channel is not required, we do not need to define it (you can use the function with only the above six parameters).
Note:in the context of "mixed type" here, please Please note that the "mixed" keyword in PHP is not a primitive type and cannot be used in programming. Mixed type is used here to convey that the type can be of any type.Return value:The function returns True on success.Below is an example of a function Imagick::floodFillPaintImage() in PHP:Example:Consider two blocks, one black and one green (190x90): Now we will write a PHP program that illustrates the Imagick::floodFillPaintImage() function .
  • Program : // Create new imagick objects for blocks under the same name: $imagick = new Imagick ( ’https: // content / uploads / 20190720123909 / black1.png " alt = "" width = "190" height = " 90 " class = "alignnone size-full wp-image-1167659’); $imagick = new Imagick ( ’https: //" alt = "" width = "190" height = "90" class = "alignnone size-full wp-image-1167665’); // Add images into one: $imagick -> resetIterator(); $combined = $imagick -> appendImages (true); // Save the image for comparison: $combined -> writeImage ( "blackgreenobjects.png" ); // Set (x, y) values ​​for the target pixel to draw: $x = 1; $y = 1; // Get the color we’re drawing: $target = $combined -> getImagePixelColor ( $x , $y ); // Draws a pixel at position (1, 1) and all adjacent pixels // that match the target color (black) green: $combined -> floodfillPaintImage ( "green" , 1, $target , $x , $y , false); // Save the resulting image: $combined -> writeImage ( "greengreenfill.png" ); // Display the resulting image: echo $combined ;  
  • Output:this code first creates two Imagick objects under the same name, a black and green block, and then adds them into one (successive objects are added under the first object).
    • The saved image looks like this:
    • Then using the floodfillPaintImage() function, we paint / fill the pixel at position (x = 1, y = 1) and its neighboring pixels from the same color to green. the pixel at position (1, 1) is colored black (like its first block), and, therefore, this pixel, together with neighboring pixels of black color (in the chain, until the color changes, the fill goes like a "flow" spreading), get filled with our data in green. 
      The saved image looks like this:
    Note:if you use the function again with a green target color, both of our originally defined blocks will change to fill color, because they both now have the same same color.


    Best laptop for Sims 4


    Best laptop for Zoom


    Best laptop for Minecraft


    Best laptop for engineering student


    Best laptop for development


    Best laptop for Cricut Maker


    Best laptop for hacking


    Best laptop for Machine Learning


    Latest questions


    psycopg2: insert multiple rows with one query

    12 answers


    How to convert Nonetype to int or string?

    12 answers


    How to specify multiple return types using type-hints

    12 answers


    Javascript Error: IPython is not defined in JupyterLab

    12 answers



    Python OpenCV | cv2.putText () method

    numpy.arctan2 () in Python

    Python | os.path.realpath () method

    Python OpenCV | () method

    Python OpenCV cv2.cvtColor () method

    Python - Move item to the end of the list

    time.perf_counter () function in Python

    Check if one list is a subset of another in Python

    Python os.path.join () method