note 60449 added to function.imageconvolution
| From: | dyer85 at gmail dot com | Date: | Sat, 07 Jan 2006 10:24:06 +0000 |
| Subject: | note 60449 added to function.imageconvolution | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-101348@lists.php.net to get a copy of this message | ||
Took me a while, but thanks to a couple of the user notes on the array_values PHP documentation
page, I was able to come up with a way to dynamically compute the divisor.
I'm using PHP 5.1.0b2 on Win32 with the bundled GD library. When I try and use the
imageconvolution function, whether normally, or via the functions below, the resulting image
(I've only tried JPEGs and GIFs), always comes out far too bright, even when the divisor makes
matrix sum equal to 1. The only thing that would reduce the brightness was to make the offset
argument ridiculously large. So, I'm not sure if this effects anyone else.
Here are the functions with an example:
<?php
$im = imagecreatefromjpeg('path/to/pic.jpg');
$matrix = array( array(5,5,5),
array(5,15,5),
array(5,5,5) );
makeFilter($im, $matrix);
header ( 'Content-Type: image/jpeg' );
imagejpeg($im);
imagedestroy($im);
/**
* functions
*/
// This flattens the 3X3 array matrix, so we can get the sum of all the values
function array_flatten($array) {
(array)$tempArray = array();
foreach ( $array as $value ) {
if ( is_array($value) ) {
$tempArray = array_merge($tempArray, array_flatten($value));
} else {
$tempArray[] = $value;
}
}
return $tempArray;
}
// Creates the divisor value dynamically, and passes offset
function makeFilter($resource, $matrix, $offset=1.0) {
global $$resource;
(float)$divisor = array_sum(array_flatten($matrix));
return imageconvolution($resource, $matrix, $divisor, $offset) ? true : false;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.imageconvolution.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60449
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60449&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60449&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60449&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60449&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60449&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60449&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60449&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60449&report=yes
Search -- http://master.php.net/manage/user-notes.php