I have image with white background and in that image i have some kind of shape - part of cloth. I need to find most left, up, right and bottom pixel. What is the most efficient way to do that?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can use the trimImage function to trim the image, and then look at the geometry and page info to find how the bounding box of the image that was left after trimming.
$base = new Imagick(realpath('./trim.png'));
$base->trimImage(0);
$geometry = $base->getImageGeometry();
$pageInfo = $base->getImagePage();
printf (
"Width %d Height %d\n",
$geometry['width'],
$geometry['height']
);
printf(
"OffsetX: %d OffsetY %d\n",
$pageInfo['x'],
$pageInfo['y']
);