我有一些图像,它们中的每一个都有一个相同大小的遮罩(透明)矩形区域。如何检测这些区域的坐标?我搜索了库,但没有一个库能做到这一点。我想把我的二维码而不是蒙面部分放进去。
发布于 2021-07-21 23:21:12
我会尝试(未测试)读取图像并使用透明颜色:
$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
}
}
}
https://stackoverflow.com/questions/68471880
复制相似问题