【发布时间】:2021-09-28 23:16:36
【问题描述】:
我有一些图像,每个图像都有一个相同大小的蒙版(透明)矩形区域。如何检测这些区域的坐标?我搜索了图书馆,但没有一个人这样做。我想放我的二维码而不是蒙面部分。
【问题讨论】:
标签: php image png mask masking
我有一些图像,每个图像都有一个相同大小的蒙版(透明)矩形区域。如何检测这些区域的坐标?我搜索了图书馆,但没有一个人这样做。我想放我的二维码而不是蒙面部分。
【问题讨论】:
标签: php image png mask masking
我会尝试(未经测试)读取图像并使用透明颜色:
$src = imagecreatefrompng("your-image.png");
$trans = imageColorAllocateAlpha($src, 0, 0, 0, 127);
$transArray = imagecolorsforindex($src, $trans);
我会像这样读取图像尺寸并检查每个像素:
$width = imagesx($src);
$height = imagesy($src);
for ($x = 0; $x < $width; $x++) {
for ($y = 0; $y < $height; $y++) {
$color = imagecolorat($src, $x, $y);
$colors = imagecolorsforindex($src, $color);
if ($colors["alpha"] == $transArray["alpha"]) {
// you have detected the first pixel of transparency
// here you have to remember smallest $x and smallest $y
// as well as biggest $x and biggest $y
// that should be your rectangle
}
}
}
【讨论】: