我想循环遍历图像的所有像素,找到该像素的rgba值,并对这些像素执行某些操作.
假设我的图像是100x100像素.我想用我已经做过的函数找到每个像素的值:
function getPixel($image, $x, $y) {
$colors = imagecolorsforindex($image, imagecolorat($image, $x, $y));
$inrgba = 'rgba(' . $colors['red'] . ',' . $colors['green'] . ',' . $colors['blue'] . ',' . $colors['alpha'] . ')';
return $inrgba;
}
Run Code Online (Sandbox Code Playgroud)
并将这些值以及图像的尺寸存储在数组或数组数组中.我想在html页面中使用最终结果.
我该怎么做呢?
for($x=1;$x<=$width;$x++)
{
for($y=1;$y<=$height;$y++)
{
$pixel=getPixel($image, $x, $y);
//do something
}
}
Run Code Online (Sandbox Code Playgroud)
这样做是找到每列中的每个像素.
i=iteration
pixel coordinate = (x,y)
Run Code Online (Sandbox Code Playgroud)
对于5 x 5图像,迭代看起来像这样:
i1 = (1,1)
i2 = (1,2)
i3 = (1,3)
i4 = (1,4)
i5 = (1,5)
i6 = (2,1)
i7 = (2,2)
i8 = (2,3)
i9 = (2,4)
i10 = (2,5)
i11 = (3,1)
i12 = (3,2)
i13 = (3,3)
i14 = (3,4)
i15 = (3,5)
i16 = (4,1)
i17 = (4,2)
i18 = (4,3)
i19 = (4,4)
i20 = (4,5)
i21 = (5,1)
i22 = (5,2)
i23 = (5,3)
i24 = (5,4)
i25 = (5,5)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6408 次 |
| 最近记录: |