<?php

$src_image  
"smoking-woman";
$src_type   ".jpg";
$quality    100;

switch(
$src_type)
{
    case 
'.jpeg':
    case  
'.jpg':
        
$image_create "imagecreatefromjpeg";
        break;
    case  
'.png':
        
$image_create "imagecreatefrompng";
        break;
    default:
        echo 
'image type should be either .jpg or .png';
        exit;
}

switch(
$src_type)
{
    case 
'.jpeg':
    case  
'.jpg':
        
$image_out "imagejpeg";
        break;
    case  
'.png':
        
$image_out "imagepng";
        break;
    default:
        echo 
'image type should be either .jpg or .png';
        exit;
}

if (
$src_type == '.png')
{
    
$quality = (int) ((100 $quality) * (100));
}

$source $image_create($src_image $src_type);
imagealphablending($sourcefalse);
imagesavealpha($sourcetrue);

$source_width imagesx($source);
$source_height imagesy($source);

/********************************************/
/* start imageconvolution2 without negation */
/********************************************/
$new_image $image_create($src_image $src_type);
imagealphablending($new_imagefalse);
imagesavealpha($new_imagetrue);

/* 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$my10) ? '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($combinedtrue);
imagesavealpha($combinedtrue);
$trans imagecolorallocatealpha($combined000127);
imagefill($combined00$trans);
imagecopy($combined$source0000$source_width$source_height);
imagecopy($combined$new_image$source_width000$source_width$source_height);

$image_out($combined$src_image "-imageconvolution2-combined" $src_type$quality);

imagedestroy($new_image);
imagedestroy($combined);
/* end imageconvolution2 without negation */


/*****************************************/
/* start imageconvolution2 with negation */
/*****************************************/
$new_image $image_create($src_image $src_type);
imagealphablending($new_imagefalse);
imagesavealpha($new_imagetrue);

echo 
'Running image through imageconvolution2 with negation.... ';
echo 
imageconvolution2($new_image$mx$my10true) ? '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($combinedtrue);
imagesavealpha($combinedtrue);
$trans imagecolorallocatealpha($combined000127);
imagefill($combined00$trans);
imagecopy($combined$source0000$source_width$source_height);
imagecopy($combined$new_image$source_width000$source_width$source_height);

$image_out($combined$src_image "-imageconvolution2-combined-negate" $src_type$quality);

imagedestroy($new_image);
imagedestroy($combined);
/* end imageconvolution2 with negation */


/*********************************************************/
/* start imagefilter IMG_FILTER_PREWITT without negation */
/*********************************************************/
$new_image $image_create($src_image $src_type);
imagealphablending($new_imagefalse);
imagesavealpha($new_imagetrue);

echo 
'Running image through imagefilter with IMG_FILTER_PREWITT without negation.... ';
echo 
imagefilter($new_imageIMG_FILTER_PREWITTfalse) ? '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($combinedtrue);
imagesavealpha($combinedtrue);
$trans imagecolorallocatealpha($combined000127);
imagefill($combined00$trans);
imagecopy($combined$source0000$source_width$source_height);
imagecopy($combined$new_image$source_width000$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 */



/******************************************************/
/* start imagefilter IMG_FILTER_PREWITT with negation */
/******************************************************/
$new_image $image_create($src_image $src_type);
imagealphablending($new_imagefalse);
imagesavealpha($new_imagetrue);

echo 
'Running image through imagefilter with IMG_FILTER_PREWITT with negation.... ';
echo 
imagefilter($new_imageIMG_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($combinedtrue);
imagesavealpha($combinedtrue);
$trans imagecolorallocatealpha($combined000127);
imagefill($combined00$trans);
imagecopy($combined$source0000$source_width$source_height);
imagecopy($combined$new_image$source_width000$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 */

/********************************************************/
/* start imagefilter IMG_FILTER_SCHARR without negation */
/********************************************************/
$new_image $image_create($src_image $src_type);
imagealphablending($new_imagefalse);
imagesavealpha($new_imagetrue);

echo 
'Running image through imagefilter with IMG_FILTER_SCHARR without negation.... ';
echo 
imagefilter($new_imageIMG_FILTER_SCHARRfalse) ? '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($combinedtrue);
imagesavealpha($combinedtrue);
$trans imagecolorallocatealpha($combined000127);
imagefill($combined00$trans);
imagecopy($combined$source0000$source_width$source_height);
imagecopy($combined$new_image$source_width000$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 */


/*****************************************************/
/* start imagefilter IMG_FILTER_SCHARR with negation */
/*****************************************************/
$new_image $image_create($src_image $src_type);
imagealphablending($new_imagefalse);
imagesavealpha($new_imagetrue);

echo 
'Running image through imagefilter with IMG_FILTER_SCHARR with negation.... ';
echo 
imagefilter($new_imageIMG_FILTER_SCHARR) ? '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($combinedtrue);
imagesavealpha($combinedtrue);
$trans imagecolorallocatealpha($combined000127);
imagefill($combined00$trans);
imagecopy($combined$source0000$source_width$source_height);
imagecopy($combined$new_image$source_width000$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 */


/*******************************************************/
/* start imagefilter IMG_FILTER_SOBEL without negation */
/*******************************************************/
$new_image $image_create($src_image $src_type);
imagealphablending($new_imagefalse);
imagesavealpha($new_imagetrue);

echo 
'Running image through imagefilter with IMG_FILTER_SOBEL without negation.... ';
echo 
imagefilter($new_imageIMG_FILTER_SOBELfalse) ? '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($combinedtrue);
imagesavealpha($combinedtrue);
$trans imagecolorallocatealpha($combined000127);
imagefill($combined00$trans);
imagecopy($combined$source0000$source_width$source_height);
imagecopy($combined$new_image$source_width000$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 */


/****************************************************/
/* start imagefilter IMG_FILTER_SOBEL with negation */
/****************************************************/
$new_image $image_create($src_image $src_type);
imagealphablending($new_imagefalse);
imagesavealpha($new_imagetrue);

echo 
'Running image through imagefilter with IMG_FILTER_SOBEL with negation.... ';
echo 
imagefilter($new_imageIMG_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($combinedtrue);
imagesavealpha($combinedtrue);
$trans imagecolorallocatealpha($combined000127);
imagefill($combined00$trans);
imagecopy($combined$source0000$source_width$source_height);
imagecopy($combined$new_image$source_width000$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 */

?>