php +html怎么自动\生成coords坐标?
时间: 2024-05-04 13:16:17 浏览: 68
您好!关于您的问题,您可以使用如下的代码片段自动生成coords坐标:
```php
<?php
function get_coords($img_path, $shape) {
$width = $shape[0];
$height = $shape[1];
$coords = '';
// loop through each pixel
for ($y = 0; $y < $height; $y++) {
for ($x = 0; $x < $width; $x++) {
$rgb = imagecolorat($img_path, $x, $y);
$color = imagecolorsforindex($img_path, $rgb);
// if pixel is not white, add coords
if ($color['red'] < 255 || $color['green'] < 255 || $color['blue'] < 255) {
$coords .= "$x, $y, ";
}
}
}
// remove last comma and space
$coords = substr($coords, 0, -2);
return $coords;
}
```
使用方法:
```php
<?php
$img_path = 'path/to/image.png';
$shape = getimagesize($img_path);
$coords = get_coords($img_path, $shape);
echo $coords;
?>
```
希望这能够帮到您!
阅读全文