note 77818 added to function.imageconvolution
| From: | Jase at osu1 dot php dot net | Date: | Thu, 13 Sep 2007 22:53:11 +0000 |
| Subject: | note 77818 added to function.imageconvolution | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130485@lists.php.net to get a copy of this message | ||
The comment below is an extremely good workaround
however, php did throw lots of warnings at me when i had error reporting set to E_ALL
this can be avoided with one line of code and no impact (as i can see) to the rest of the function
<?php
//include this file whenever you have to use imageconvolution...
//you can use in your project, but keep the comment below :)
//great for any image manipulation library
//Made by Chao Xu(Mgccl) 2/28/07
//www.webdevlogs.com
//V 1.0
if(!function_exists('imageconvolution')){
function imageconvolution($src, $filter, $filter_div, $offset){
if ($src==NULL) {
return 0;
}
$sx = imagesx($src);
$sy = imagesy($src);
$srcback = ImageCreateTrueColor ($sx, $sy);
ImageCopy($srcback, $src,0,0,0,0,$sx,$sy);
if($srcback==NULL){
return 0;
}
#FIX HERE
#$pxl array was the problem so simply set it with very low values
$pxl = array(1,1);
#this little fix worked for me as the undefined array threw out errors
for ($y=0; $y<$sy; ++$y){
for($x=0; $x<$sx; ++$x){
$new_r = $new_g = $new_b = 0;
$alpha = imagecolorat($srcback, $pxl[0], $pxl[1]);
$new_a = $alpha >> 24;
for ($j=0; $j<3; ++$j) {
$yv = min(max($y - 1 + $j, 0), $sy - 1);
for ($i=0; $i<3; ++$i) {
$pxl = array(min(max($x - 1 + $i, 0), $sx - 1), $yv);
$rgb = imagecolorat($srcback, $pxl[0], $pxl[1]);
$new_r += (($rgb >> 16) & 0xFF) * $filter[$j][$i];
$new_g += (($rgb >> 8) & 0xFF) * $filter[$j][$i];
$new_b += ($rgb & 0xFF) * $filter[$j][$i];
}
}
$new_r = ($new_r/$filter_div)+$offset;
$new_g = ($new_g/$filter_div)+$offset;
$new_b = ($new_b/$filter_div)+$offset;
$new_r = ($new_r > 255)? 255 : (($new_r < 0)? 0:$new_r);
$new_g = ($new_g > 255)? 255 : (($new_g < 0)? 0:$new_g);
$new_b = ($new_b > 255)? 255 : (($new_b < 0)? 0:$new_b);
$new_pxl = ImageColorAllocateAlpha($src, (int)$new_r, (int)$new_g, (int)$new_b, $new_a);
if ($new_pxl == -1) {
$new_pxl = ImageColorClosestAlpha($src, (int)$new_r, (int)$new_g, (int)$new_b,
$new_a);
}
if (($y >= 0) && ($y < $sy)) {
imagesetpixel($src, $x, $y, $new_pxl);
}
}
}
imagedestroy($srcback);
return 1;
}
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 79.72.255.18
----
Manual Page -- http://www.php.net/manual/en/function.imageconvolution.php
Edit -- https://master.php.net/note/edit/77818
Del: integrated -- https://master.php.net/note/delete/77818/integrated
Del: useless -- https://master.php.net/note/delete/77818/useless
Del: bad code -- https://master.php.net/note/delete/77818/bad+code
Del: spam -- https://master.php.net/note/delete/77818/spam
Del: non-english -- https://master.php.net/note/delete/77818/non-english
Del: in docs -- https://master.php.net/note/delete/77818/in+docs
Del: other reasons-- https://master.php.net/note/delete/77818
Reject -- https://master.php.net/note/reject/77818
Search -- https://master.php.net/manage/user-notes.php