PHP Make image sharpening processing

Source: Internet
Author: User
Tags unsupported

<?php//Read the type of image//1=gif,2=jpg,3=png,4=swf,5=psd,6=bmp,7=tiff (Intelbyteorder), 8=tiff (Motorolabyteorder), 9=JPC,10=JP2,11=JPX , 12=jb2,13=swc,14=iff function getimagetype($filename){return(($imginfo[Email protected] ($filename))!=NULL?

$imginfo[2]:NULL);}//Image Sharpening//$SCR _im: Image resource handle, $degree: Sharpening degrees 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++){/*imagecolorsforindex---Get color syntax from index values: array imagecolorsforindex (int im, int index) Description: This function returns the RGB value of the specified color index value, and the returned array has a red , green, and blue three index values, the value of the array is the RGB value of the specified color index value. Imagecolorat---Gets the color index value syntax for the pixel: int imagecolorat (int im, int x, int y) Description: Returns the color index value of the pixel at the specified position in the drawing. */$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("colorallocatefaileat$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 (Ten* -);if(($ImageType= Getimagetype ($_post["ImageName"]))==false) die("The specified file does not exist or is not a valid picture or unsupported type. ");if($ImageType==6)$ImageType=0;if($ImageType>3) die("Unsupported picture Type!

");$im 1=$ImageFunctions[$ImageType]($_post["ImageName"]);$im 2=$ImageFunctions[$ImageType]($_post["ImageName"]);//print_r (Imagecolorsforindex ($im, Imagecolorat ($im, 10,10)));Sharp ($im 1,$im 2,$_post["Degree"]); Header ("Content-type:image/png"); Imagepng ($im 2); Imagedestroy ($im 1); Imagedestroy ($im 2);}?><form name= "FormName" action= " method=" Post ">Please enter a local path or URL for the picture:<br/><input name="ImageName" type="text" value="< =$_post["ImageName"]? >"Size=32><br/>Degree of sharpening (example: 0.6, 3.0):<br/><input name="degree" type="text" value= "<?

=$_post["degree"]?

>"><br/><input type="submit" value="提交"></form>

PHP Make image sharpening processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.