public function generate() { $width = $this->_owner->imagesx(); $height = $this->_owner->imagesy(); $mx = array(array(-0, 0, 0), array(-1, 0, 1), array(-0, 0, 0)); $my = array(array(0, 1, 0), array(0, 0, 0), array(-0, -1, -0)); $m_elements = count($mx); $m_offset = floor($m_elements / 2); $p = array(); for ($y = 0; $y < $height; $y++) { for ($x = 0; $x < $width; $x++) { $rgb = $this->_owner->imagecolorat($x, $y); $arrRgb = Image_Image::intColorToArrayColor($rgb); $p[$x][$y]['r'] = $arrRgb['red']; $p[$x][$y]['g'] = $arrRgb['green']; $p[$x][$y]['b'] = $arrRgb['blue']; } } for ($y = 1; $y < $height - 1; $y++) { for ($x = 1; $x < $width - 1; $x++) { $sumXr = $sumXg = $sumXb = $sumYr = $sumYg = $sumYb = 0; for ($i = -1; $i <= 1; $i++) { for ($j = -1; $j <= 1; $j++) { $sumXr = $sumXr + $p[$x + $i][$y + $j]['r'] * $mx[$i + 1][$j + 1]; $sumXg = $sumXg + $p[$x + $i][$y + $j]['g'] * $mx[$i + 1][$j + 1]; $sumXb = $sumXb + $p[$x + $i][$y + $j]['b'] * $mx[$i + 1][$j + 1]; $sumYr = $sumYr + $p[$x + $i][$y + $j]['r'] * $my[$i + 1][$j + 1]; $sumYg = $sumYg + $p[$x + $i][$y + $j]['g'] * $my[$i + 1][$j + 1]; $sumYb = $sumYb + $p[$x + $i][$y + $j]['b'] * $my[$i + 1][$j + 1]; } } $sumr = abs($sumXr) + abs($sumYr); $sumg = abs($sumXg) + abs($sumYg); $sumb = abs($sumXb) + abs($sumYb); if ($sumr > 255) { $sumr = 255; } if ($sumg > 255) { $sumg = 255; } if ($sumb > 255) { $sumb = 255; } if ($sumr < 0) { $sumr = 0; } if ($sumg < 0) { $sumg = 0; } if ($sumb < 0) { $sumb = 0; } $color = imagecolorallocate($this->_owner->image, 255 - $sumr, 255 - $sumg, 255 - $sumb); imagesetpixel($this->_owner->image, $x, $y, $color); } } return true; }
public function generate() { $width = $this->_owner->imagesx(); $height = $this->_owner->imagesy(); $distance = $this->distance; $matrix = $this->matrix; $matrix_width = count($matrix); $matrix_sum = array_sum($matrix); $c = 0; $m_offset = floor($matrix_width / 2); $temp = new Image_Image(); $temp->createImageTrueColorTransparent($width + $matrix_width * 2, $height + $matrix_width * 2); imagecopy($temp->image, $this->_owner->image, $matrix_width, $matrix_width, 0, 0, $width, $height); $w = $temp->imagesx(); $h = $temp->imagesy(); for ($y = 0; $y < $h; $y++) { for ($x = 0; $x < $w; $x++) { $t = $temp->imagecolorat($x, $y); $t1 = Image_Image::intColorToArrayColor($t); $p[$x][$y]['r'] = $t1['red']; $p[$x][$y]['g'] = $t1['green']; $p[$x][$y]['b'] = $t1['blue']; $p[$x][$y]['a'] = $t1['alpha']; $p1[$x][$y]['r'] = 255; $p1[$x][$y]['g'] = 255; $p1[$x][$y]['b'] = 255; $p1[$x][$y]['a'] = 127; } } $w = $this->_owner->imagesx(); $h = $this->_owner->imagesy(); $d_offset = $distance - $matrix_width; if ($this->color != "image") { $arrColor = $this->_owner->hexColorToArrayColor($this->color); } $temp->createImageTrueColorTransparent($width + $distance + $m_offset, $height + $distance + $m_offset); imagesavealpha($temp->image, true); imagealphablending($temp->image, true); for ($i = $m_offset; $i < $w + $m_offset + $matrix_width; $i++) { for ($j = $m_offset; $j < $h + $m_offset + $matrix_width; $j++) { $sumr = 0; $sumg = 0; $sumb = 0; $suma = 0; for ($k = 0; $k < $matrix_width; $k++) { $xx = $i - ($matrix_width >> 1) + $k; $sumr += $p[$xx][$j]['r'] * $matrix[$k]; $sumg += $p[$xx][$j]['g'] * $matrix[$k]; $sumb += $p[$xx][$j]['b'] * $matrix[$k]; $suma += $p[$xx][$j]['a'] * $matrix[$k]; } $p1[$i][$j]['r'] = $sumr / $matrix_sum; $p1[$i][$j]['g'] = $sumg / $matrix_sum; $p1[$i][$j]['b'] = $sumb / $matrix_sum; $p1[$i][$j]['a'] = $suma / $matrix_sum; } } for ($i = $m_offset; $i < $w + $m_offset + $matrix_width; $i++) { for ($j = $m_offset; $j < $h + $m_offset + $matrix_width; $j++) { $sumr = 0; $sumg = 0; $sumb = 0; $suma = 0; for ($k = 0; $k < $matrix_width; $k++) { $xy = $j - ($matrix_width >> 1) + $k; $sumr += $p1[$i][$xy]['r'] * $matrix[$k]; $sumg += $p1[$i][$xy]['g'] * $matrix[$k]; $sumb += $p1[$i][$xy]['b'] * $matrix[$k]; $suma += $p1[$i][$xy]['a'] * $matrix[$k]; } if ($this->color != "image") { $col = imagecolorallocatealpha($temp->image, $arrColor['red'], $arrColor['green'], $arrColor['blue'], $suma / $matrix_sum); } else { $col = imagecolorallocatealpha($temp->image, $sumr / $matrix_sum, $sumg / $matrix_sum, $sumb / $matrix_sum, $suma / $matrix_sum); } imagesetpixel($temp->image, $i + $d_offset, $j + $d_offset, $col); } } imagecopy($temp->image, $this->_owner->image, 0, 0, 0, 0, $width, $height); $this->_owner->image = $temp->image; unset($temp); return true; }