1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
function applyMatrix3x3($matrix)
{
$info=$this->getImageSize();
$img2=$this->imagecreate($info['w']-2,$info['h']-2);
for($x=1;$x<$info['w']-1;$x++)
{
for($y=1;$y<$info['h']-1;$y++)
{
$r=$g=$b=0;
for($Mx=0;$Mx<3;$Mx++)
{
for($My=0;$My<3;$My++)
{
$rgb=imagecolorat($this->resourceImage,$x-1+$Mx,$y-1+$My);
$r += $matrix[$Mx][$My]*(($rgb >> 16) & 0xFF); //r
$g += $matrix[$Mx][$My]*(($rgb >> 8) & 0xFF); //g
$b += $matrix[$Mx][$My]*(($rgb ) & 0xFF); //b
}
}
$r=min(255,max(0,$r));
$g=min(255,max(0,$g));
$b=min(255,max(0,$b));
if(!isset($cols[$r][$g][$b]))
{
//on minimise les allocation de couleur
$cols[$r][$g][$b]=imagecolorallocate($img2,$r,$g,$b);
}
imagesetpixel($img2,$x-1,$y-1,$cols[$r][$g][$b]);
}
}
imagedestroy($this->resourceImage);
$this->resourceImage=$img2;
} |
Partager