<?
// Read image type
// 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = tiff (Intel byte order ), 8 = tiff (Motorola byte order), 9 = JPC, 10 = JP2, 11 = JPX, 12 = jb2, 13 = SWC, 14 = IFF
Function getimagetype ($ filename) {return ($ imginfo = @ getimagesize ($ filename ))! = NULL? $ Imginfo [2]: NULL );}
// Sharpen the image
// $ Scr_im: image resource handle, $ degree: Sharpen
Function sharp (& $ src_im, & $ dst_im, $ degree)
{
$ Src_x = imagesx ($ src_im );
$ Src_y = imagesy ($ src_im );
// $ Dst_im = imagecreate ($ src_x, $ src_y );
// Imagecopy ($ dst_im, $ src_im, 0, 0, 0, 0, $ src_x, $ src_y );
$ CNT = 0;
For ($ x = 1; $ x <$ src_x; $ X ++)
For ($ y = 1; $ Y <$ src_y; $ y ++)
{
$ Src_clr1 = imagecolorsforindex ($ src_im, imagecolorat ($ src_im, $ X-1, $ Y-1 ));
$ Src_clr2 = imagecolorsforindex ($ src_im, imagecolorat ($ src_im, $ X, $ y ));
$ R = intval ($ src_clr2 ["red"] + $ degree * ($ src_clr2 ["red"]-$ src_clr1 ["red"]);
$ G = intval ($ src_clr2 ["green"] + $ degree * ($ src_clr2 ["green"]-$ src_clr1 ["green"]);
$ B = intval ($ src_clr2 ["blue"] + $ degree * ($ src_clr2 ["blue"]-$ src_clr1 ["blue"]);
$ R = min (255, max ($ R, 0 ));
$ G = min (255, max ($ g, 0 ));
$ B = min (255, max ($ B, 0 ));
// Echo "R: $ R, G: $ G, B: $ B <br/> ";
If ($ dst_clr = imagecolorexact ($ dst_im, $ R, $ g, $ B) =-1)
$ Dst_clr = imagecolorallocate ($ dst_im, $ R, $ g, $ B );
$ CNT ++;
If ($ dst_clr =-1) Die ("color allocate faile at $ X, $ Y ($ CNT ).");
Imagesetpixel ($ dst_im, $ X, $ y, $ dst_clr );
}
Return $ dst_im;
}
$ Imagefunctions = array ("imagecreatefromwbmp", "imagecreatefromgif", "imagecreatefromjpeg", "imagecreatefrompng ");
If (! Empty ($ _ post ["imagename"])
{
Set_time_limit (10*60 );
If ($ imagetype = getimagetype ($ _ post ["imagename"]) = false)
Die ("the specified file does not exist or is not a valid image or does not support the type! ");
If ($ imagetype = 6) $ imagetype = 0;
If ($ imagetype> 3) Die ("unsupported image type! ");
$ Im1 = $ imagefunctions [$ imagetype] ($ _ post ["imagename"]);
$ IM2 = $ imagefunctions [$ imagetype] ($ _ post ["imagename"]);
// Print_r (imagecolorsforindex ($ im, imagecolorat ($ im, 10, 10 )));
Sharp ($ im1, $ IM2, $ _ post ["degree"]);
Header ("Content-Type: image/PNG ");
Imagepng ($ IM2 );
Imagedestroy ($ im1 );
Imagedestroy ($ IM2 );
}
?>
<Form name = "formname" Action = "" method = "Post">
Enter the local path or URL of the image: <br/>
<Input name = "imagename" type = "text" value = "<? =_ _ Post ["imagename"]?> "Size = 32> <br/>
Sharpen degree (for example, 0.6, 3.0): <br/>
<Input name = "degree" type = "text" value = "<? =_ _ Post ["degree"]?> "> <Br/>
<Input type = "Submit" value = "Submit">
</Form>
Changed the value and saved a $ IM:
Function sharp2 (& $ im, $ degree)
{
$ CNT = 0;
For ($ x = imagesx ($ IM)-1; $ x> 0; $ X --)
For ($ Y = imagesy ($ IM)-1; $ Y> 0; $ y --)
{
$ Clr1 = imagecolorsforindex ($ im, imagecolorat ($ im, $ X-1, $ Y-1 ));
$ Clr2 = imagecolorsforindex ($ im, imagecolorat ($ im, $ X, $ y ));
$ R = intval ($ clr2 ["red"] + $ degree * ($ clr2 ["red"]-$ clr1 ["red"]);
$ G = intval ($ clr2 ["green"] + $ degree * ($ clr2 ["green"]-$ clr1 ["green"]);
$ B = intval ($ clr2 ["blue"] + $ degree * ($ clr2 ["blue"]-$ clr1 ["blue"]);
$ R = min (255, max ($ R, 0 ));
$ G = min (255, max ($ g, 0 ));
$ B = min (255, max ($ B, 0 ));
// Echo "R: $ R, G: $ G, B: $ B <br> ";
If ($ new_clr = imagecolorexact ($ im, $ R, $ g, $ B) =-1)
$ New_clr = imagecolorallocate ($ im, $ R, $ g, $ B );
$ CNT ++;
If ($ new_clr =-1) Die ("color allocate faile at $ X, $ Y ($ CNT ).");
Imagesetpixel ($ im, $ X, $ y, $ new_clr );
}
}