This patch adds three additional image filters to PHP's imagefilter() function. The patch file can be found here. The source for my test script can be viewed here. The original source image can be found here. As a by-product of these additions, the patch makes an additional function (imageconvolution2) available for PHP scripting.
<?php /*********************************************************/ /* start imagefilter IMG_FILTER_PREWITT without negation */ /*********************************************************/ $new_image = $image_create($src_image . $src_type); imagealphablending($new_image, false); imagesavealpha($new_image, true); echo 'Running image through imagefilter with IMG_FILTER_PREWITT without negation.... '; echo imagefilter($new_image, IMG_FILTER_PREWITT, false) ? 'done OK' : 'done with ERRORS'; echo "\x0a"; $image_out($new_image, $src_image . "-imagefilter-prewitt" . $src_type, $quality); $combined = imagecreatetruecolor($source_width * 2, $source_height); imagealphablending($combined, true); imagesavealpha($combned, true); $trans = imagecolorallocatealpha($combined, 0, 0, 0, 127); imagefill($combined, 0, 0, $trans); imagecopy($combined, $source, 0, 0, 0, 0, $source_width, $source_height); imagecopy($combined, $new_image, $source_width, 0, 0, 0, $source_width, $source_height); $image_out($combined, $src_image . "-imagefilter-prewitt-combined" . $src_type, $quality); imagedestroy($new_image); imagedestroy($combined); /* end imagefilter IMG_FILTER_PREWITT without negation */ ?>
Resulting combined image....
<?php /******************************************************/ /* start imagefilter IMG_FILTER_PREWITT with negation */ /******************************************************/ $new_image = $image_create($src_image . $src_type); imagealphablending($new_image, false); imagesavealpha($new_image, true); echo 'Running image through imagefilter with IMG_FILTER_PREWITT with negation.... '; echo imagefilter($new_image, IMG_FILTER_PREWITT) ? 'done OK' : 'done with ERRORS'; echo "\x0a"; $image_out($new_image, $src_image . "-imagefilter-prewitt-negate" . $src_type, $quality); $combined = imagecreatetruecolor($source_width * 2, $source_height); imagealphablending($combined, true); imagesavealpha($combned, true); $trans = imagecolorallocatealpha($combined, 0, 0, 0, 127); imagefill($combined, 0, 0, $trans); imagecopy($combined, $source, 0, 0, 0, 0, $source_width, $source_height); imagecopy($combined, $new_image, $source_width, 0, 0, 0, $source_width, $source_height); $image_out($combined, $src_image . "-imagefilter-prewitt-combined-negate" . $src_type, $quality); imagedestroy($new_image); imagedestroy($combined); /* end imagefilter IMG_FILTER_PREWITT with negation */ ?>
Resulting combined image....
<?php /********************************************************/ /* start imagefilter IMG_FILTER_SCHARR without negation */ /********************************************************/ $new_image = $image_create($src_image . $src_type); imagealphablending($new_image, false); imagesavealpha($new_image, true); echo 'Running image through imagefilter with IMG_FILTER_SCHARR without negation.... '; echo imagefilter($new_image, IMG_FILTER_SCHARR, false) ? 'done OK' : 'done with ERRORS'; echo "\x0a"; $image_out($new_image, $src_image . "-imagefilter-scharr" . $src_type, $quality); $combined = imagecreatetruecolor($source_width * 2, $source_height); imagealphablending($combined, true); imagesavealpha($combned, true); $trans = imagecolorallocatealpha($combined, 0, 0, 0, 127); imagefill($combined, 0, 0, $trans); imagecopy($combined, $source, 0, 0, 0, 0, $source_width, $source_height); imagecopy($combined, $new_image, $source_width, 0, 0, 0, $source_width, $source_height); $image_out($combined, $src_image . "-imagefilter-scharr-combined" . $src_type, $quality); imagedestroy($new_image); imagedestroy($combined); /* end imagefilter IMG_FILTER_SCHARR */ ?>
Resulting combined image....
<?php /*****************************************************/ /* start imagefilter IMG_FILTER_SCHARR with negation */ /*****************************************************/ $new_image = $image_create($src_image . $src_type); imagealphablending($new_image, false); imagesavealpha($new_image, true); echo 'Running image through imagefilter with IMG_FILTER_SCHARR with negation.... '; echo imagefilter($new_image, IMG_FILTER_SCHARR, false) ? 'done OK' : 'done with ERRORS'; echo "\x0a"; $image_out($new_image, $src_image . "-imagefilter-scharr-negate" . $src_type, $quality); $combined = imagecreatetruecolor($source_width * 2, $source_height); imagealphablending($combined, true); imagesavealpha($combned, true); $trans = imagecolorallocatealpha($combined, 0, 0, 0, 127); imagefill($combined, 0, 0, $trans); imagecopy($combined, $source, 0, 0, 0, 0, $source_width, $source_height); imagecopy($combined, $new_image, $source_width, 0, 0, 0, $source_width, $source_height); $image_out($combined, $src_image . "-imagefilter-scharr-combined-negate" . $src_type, $quality); imagedestroy($new_image); imagedestroy($combined); /* end imagefilter IMG_FILTER_SCHARR with negation */ ?>
Resulting combined image....
<?php /*******************************************************/ /* start imagefilter IMG_FILTER_SOBEL without negation */ /*******************************************************/ $new_image = $image_create($src_image . $src_type); imagealphablending($new_image, false); imagesavealpha($new_image, true); echo 'Running image through imagefilter with IMG_FILTER_SOBEL without negation.... '; echo imagefilter($new_image, IMG_FILTER_SOBEL, false) ? 'done OK' : 'done with ERRORS'; echo "\x0a"; $image_out($new_image, $src_image . "-imagefilter-sobel" . $src_type, $quality); $combined = imagecreatetruecolor($source_width * 2, $source_height); imagealphablending($combined, true); imagesavealpha($combned, true); $trans = imagecolorallocatealpha($combined, 0, 0, 0, 127); imagefill($combined, 0, 0, $trans); imagecopy($combined, $source, 0, 0, 0, 0, $source_width, $source_height); imagecopy($combined, $new_image, $source_width, 0, 0, 0, $source_width, $source_height); $image_out($combined, $src_image . "-imagefilter-sobel-combined" . $src_type, $quality); imagedestroy($new_image); imagedestroy($combined); /* end imagefilter IMG_FILTER_SOBEL without negation */ ?>
Resulting combined image....
<?php /****************************************************/ /* start imagefilter IMG_FILTER_SOBEL with negation */ /****************************************************/ $new_image = $image_create($src_image . $src_type); imagealphablending($new_image, false); imagesavealpha($new_image, true); echo 'Running image through imagefilter with IMG_FILTER_SOBEL with negation.... '; echo imagefilter($new_image, IMG_FILTER_SOBEL) ? 'done OK' : 'done with ERRORS'; echo "\x0a"; $image_out($new_image, $src_image . "-imagefilter-sobel-negate" . $src_type, $quality); $combined = imagecreatetruecolor($source_width * 2, $source_height); imagealphablending($combined, true); imagesavealpha($combned, true); $trans = imagecolorallocatealpha($combined, 0, 0, 0, 127); imagefill($combined, 0, 0, $trans); imagecopy($combined, $source, 0, 0, 0, 0, $source_width, $source_height); imagecopy($combined, $new_image, $source_width, 0, 0, 0, $source_width, $source_height); $image_out($combined, $src_image . "-imagefilter-sobel-combined-negate" . $src_type, $quality); imagedestroy($new_image); imagedestroy($combined); /* end imagefilter IMG_FILTER_SOBEL with negation */ ?>
Resulting combined image....
<?php
/********************************************/
/* start imageconvolution2 without negation */
/********************************************/
$new_image = $image_create($src_image . $src_type);
imagealphablending($new_image, false);
imagesavealpha($new_image, true);
/* these are the sobel matrices */
$mx = array(array( 1, 0, -1),
array( 2, 0, -2),
array( 1, 0, -1));
$my = array(array( 1, 2, 1),
array( 0, 0, 0),
array(-1, -2, -1));
echo 'Running image through imageconvolution2 without negation.... ';
echo imageconvolution2($new_image, $mx, $my, 1, 0) ? 'done OK' : 'done with ERRORS';
echo "\x0a";
$image_out($new_image, $src_image . "-imageconvolution2" . $src_type, $quality);
$combined = imagecreatetruecolor($source_width * 2, $source_height);
imagealphablending($combined, true);
imagesavealpha($combned, true);
$trans = imagecolorallocatealpha($combined, 0, 0, 0, 127);
imagefill($combined, 0, 0, $trans);
imagecopy($combined, $source, 0, 0, 0, 0, $source_width, $source_height);
imagecopy($combined, $new_image, $source_width, 0, 0, 0, $source_width, $source_height);
$image_out($combined, $src_image . "-imageconvolution2-combined" . $src_type, $quality);
imagedestroy($new_image);
imagedestroy($combined);
/* end imageconvolution2 without negation */
?>
Resulting combined image....
/*****************************************/ /* start imageconvolution2 with negation */ /*****************************************/ $new_image = $image_create($src_image . $src_type); imagealphablending($new_image, false); imagesavealpha($new_image, true); echo 'Running image through imageconvolution2 with negation.... '; echo imageconvolution2($new_image, $mx, $my, 1, 0, true) ? 'done OK' : 'done with ERRORS'; echo "\x0a"; $image_out($new_image, $src_image . "-imageconvolution2-negate" . $src_type, $quality); $combined = imagecreatetruecolor($source_width * 2, $source_height); imagealphablending($combined, true); imagesavealpha($combned, true); $trans = imagecolorallocatealpha($combined, 0, 0, 0, 127); imagefill($combined, 0, 0, $trans); imagecopy($combined, $source, 0, 0, 0, 0, $source_width, $source_height); imagecopy($combined, $new_image, $source_width, 0, 0, 0, $source_width, $source_height); $image_out($combined, $src_image . "-imageconvolution2-combined-negate" . $src_type, $quality); imagedestroy($new_image); imagedestroy($combined); /* end imageconvolution2 with negation */ ?>
Resulting combined image....