简体   繁体   中英

FloodFillPaintImage x start position and y start position

I am new at Imagick. I am trying to floodFillPaintImage from all the corner of image.

<?php
$im = new Imagick("test.jpg");
$im->scaleImage(0, 200);
$backgroundColor = $im->getImageBackgroundColor();
$im->floodfillPaintImage(new ImagickPixel('transparent'),300,$backgroundColor,0,0,false);
$im->floodfillPaintImage(new ImagickPixel('transparent'),300,$backgroundColor,200,0,false);
$im->trimImage(10);
$im->writeImage("test2.jpg");
$im->destroy();

In first case when x start position and y start position is 0 and 0 respectability, it works. But when I try x start position as 200 and y start position as 0. It throws an error.

My image is suppose to be of 200x200 and my code is suppose to run without any error. But, it doesn't run.

When I am giving x start position as 150 and y start position as 0. Then it works.

You are attempting to flood-fill from outside the image boundary.

A 200x200 pixel image has coordinates ranging from (0, 0) to (199, 199).

More generally, a W * H pixel image has coordinates ranging from (0, 0) to (W-1, H-1).


After reading your comments, it seems that you are expecting the image to have been scaled to 200x200 pixels. Hopefully the following will help:

$im = new Imagick("test.jpg");

$im->scaleImage(0, 200);
list($w, $h) = array_values($im->getImageGeometry());

$backgroundColor  = $im->getImageBackgroundColor();
$transparentColor = new ImagickPixel('transparent');

$im->floodfillPaintImage($transparentColor, 300, $backgroundColor, 0,      0,      false);
$im->floodfillPaintImage($transparentColor, 300, $backgroundColor, $w - 1, 0,      false);
$im->floodfillPaintImage($transparentColor, 300, $backgroundColor, 0,      $h - 1, false);
$im->floodfillPaintImage($transparentColor, 300, $backgroundColor, $w - 1, $h - 1, false);

$im->trimImage(10);
$im->writeImage("test2.jpg");

$im->destroy();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM