note 93223 added to function.imagesetpixel
| From: | caffinated at osu1 dot php dot net | Date: | Sat, 29 Aug 2009 00:21:33 +0000 |
| Subject: | note 93223 added to function.imagesetpixel | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-160011@lists.php.net to get a copy of this message | ||
Want to have some fun with this function? How about edge detection! (ported from http://bitecode.co.uk/2008/07/edge-detection-in-python/)
<?php
function edge($input, $output)
{
$in_im = imageCreateFromJpeg($input);
$gx = array(array(-1, 0, 1), array(-2, 0, 2), array(-1, 0, 1));
$gy = array(array(-1, -2, -1), array(0, 0, 0), array(1, 2, 1));
$x = imagesx($in_im);
$y = imagesy($in_im);
$out_im = imagecreatetruecolor($x, $y);
$colors = array(255 => imagecolorallocate($out_im, 255, 255, 255));
for ($row = 1; $row < $x; $row++)
{
for ($col = 1; $col < $y; $col++)
{
$eyedropper =imagecolorat($in_im, $x, $y);
$color =imagecolorsforindex($in_im, $eyedropper);
$pxval = ($color['red'] + $color['green'] + $color['blue']) / 3;
$pixel_gx = $pixel_gy = 0;
for ($i = -1; $i < 2; $i++)
{
for ($j = -1; $j < 2; $j++)
{
$eyedropper =imagecolorat($in_im, $row+$i, $col+$j);
$color =imagecolorsforindex($in_im, $eyedropper);
$val = ($color['red'] + $color['green'] + $color['blue']) /
3;
$pixel_gx += $gx[$i+1][$j+1] * $val;
$pixel_gy += $gy[$i+1][$j+1] * $val;
}
}
$pixel = sqrt($pixel_gx * $pixel_gx + $pixel_gy * $pixel_gy);
$pixel = abs(255 - (int)$pixel);
if (!isset($colors[$pixel])) $colors[$pixel] = imagecolorallocate($out_im, $pixel, $pixel,
$pixel);
imageSetPixel($out_im, $row, $col, $colors[$pixel]);
}
}
imagejpeg($out_im,$output, 75);
}
edge('input.jpg', 'output.jpg');
?>
----
Server IP: 72.55.140.6
Probable Submitter: 70.66.128.233
----
Manual Page -- http://www.php.net/manual/en/function.imagesetpixel.php
Edit -- https://master.php.net/note/edit/93223
Del: integrated -- https://master.php.net/note/delete/93223/integrated
Del: useless -- https://master.php.net/note/delete/93223/useless
Del: bad code -- https://master.php.net/note/delete/93223/bad+code
Del: spam -- https://master.php.net/note/delete/93223/spam
Del: non-english -- https://master.php.net/note/delete/93223/non-english
Del: in docs -- https://master.php.net/note/delete/93223/in+docs
Del: other reasons-- https://master.php.net/note/delete/93223
Reject -- https://master.php.net/note/reject/93223
Search -- https://master.php.net/manage/user-notes.php