PHP image Compression Processing

Source: Internet
Author: User
Tags imagejpeg

<?phprequire dirname (__file__).'/.. /includes/common.inc.php'; $_clean=Array (); $_info=Array (); $_data=Array (); $_clean['Shopid'] =_check ($_post['Shopid']); $_clean['userId'] =_check ($_post['userId']); $oldpic= $_files['Picfile']['Tmp_name']; if($_clean['Shopid']!="'&& $_clean['userId']!="') {$_info[' State'] =0; $_info['Info'] ="'; $max _file_size=500000;//size 500kb        if($max _file_size < $oldpic ["size"]) {$_info[' State'] =2; $_info['Info'] ='file is too large';            echo _json ($_info);            Die }Else{$_SQL1="SELECT * from tb_easy_comments WHERE user = ' {$_clean[' userId ']} ' and contentId = ' {$_clean[' contentId '} '"; $_RESULT1=_query ($_SQL1); $_row1=_num_rows ($_RESULT1); if($_row1 >0) {$_info[' State'] =0; $_info['Info'] ='you have commented';                    echo _json ($_info);                    Die }Else{$width= $; $height= $; Header ('Content-type:image/jpeg,image/png,image/gif'); //Gets the width and height of the pictureList ($width _orig, $height _orig) =getimagesize ($oldpic); $ratio _orig= $width _orig/$height _orig; //calculation ratio                        if($width/$height >$ratio _orig) {$width= $height *$ratio _orig; } Else{$height= $width/$ratio _orig; }                        //Create$image _p =Imagecreatetruecolor ($width, $height); $image=imagecreatefrompng ($oldpic); Imagecopyresampled ($image _p, $image,0,0,0,0, $width, $height, $width _orig, $height _orig); $pic= Date ('Ymdhis'). Rand ( +,9999).'.'. jpg; Imagejpeg ($image _p,"d:/www/web/php_easyhunt/images/easycommentspic/". $pic, -); $_data['Info'] ="/ http". $_server['server_name'].'/images/easycommentspic/'. $pic; $_info['Data'] =$_data;                    echo _json ($_info); }            }        }Else{$_data[' State'] =5; $_data['Info'] ='wrong parameter! '; } $_info['Data'] =$_data; echo _json ($_info);//do not delete the following after the backup//require dirname (__file__). ' /.. /includes/common.inc.php ';//$_clean = Array ();//$_info = Array ();//$_data = Array ();//$_clean[' shopid '] =_check ($_post[' shopid ']);//$_clean[' userid '] =_check ($_post[' userid ');//    //$oldpic = $_files[' picfile ' [' name '];//    //post-upload name//$newpic = Date (' Ymdhis '). Rand (1000,9999). $oldpic;//    //if ($_clean[' shopid ']!= ' && $_clean[' userId ']!= ') {//    //$_info[' state '] = 0;//$_info[' info '] = ';//$max _file_size=500000; //size 500kb//if ($max _file_size < $oldpic ["size"]) {//$_info[' state '] = 2;//$_info[' info '] = ' file is too large ';//Echo _json ($_info);//Die ;//            }//            //Receive file directory//$target _path = "d:/www/web/php_easyhunt/images/companyimages/"; //if (move_uploaded_file ($_files[' picfile ' [' tmp_name '], $target _path. $newpic)) {//            }//$_data[' info '] = "http://". $_server[' server_name ']. '    /images/companyimages/'. $newpic; //}else{//$_data[' state '] = 5;//$_data[' info '] = ' parameter is wrong! ';////    }//    //$_info[' data ' = $_data;//    //Echo _json ($_info);////$image _p = Imagecreatetruecolor ($width, $height);//$type = substr ($_absolutepath,strrpos ($_absolutepath, '. ') +1); //if ($type = = "JPG" | | $type = = "JPEG" | | $type = = "jpeg") {//$image = Imagecreatefromjpeg ($_absolutepath);//} else if ($type = = "png") {//$image = imagecreatefrompng ($_absolutepath);//} else if ($type = = "gif") {//$image = imagecreatefromgif ($_absolutepath);//        }//////function Scaleimage () {///*$_absolutepath= "http://115.28.233.45/mobile_client". $_path;*///$_absolutepath= "Http://115.28.233.45/mobile_client/imgs/comments/4_220/201412270932136d2fcd32-7764-4081-9ae5-6f85bbfadf71.JPEG";//$width = $;//$height = $;//header (' content-type:image/jpeg,image/png,image/gif ');//        //Gets the width and height of the picture//list ($width _orig, $height _orig) = getimagesize ($_absolutepath);//$ratio _orig = $width _orig/$height _orig;//        //calculation ratio//if ($width/$height > $ratio _orig) {//$width = $height * $ratio _orig;//} else {//$height = $width/$ratio _orig;//        }//        //Create//$image _p = Imagecreatetruecolor ($width, $height);//$type = substr ($_absolutepath,strrpos ($_absolutepath, '. ') +1); //if ($type = = "JPG" | | $type = = "JPEG" | | $type = = "jpeg") {//$image = Imagecreatefromjpeg ($_absolutepath);//} else if ($type = = "png") {//$image = imagecreatefrompng ($_absolutepath);//} else if ($type = = "gif") {//$image = imagecreatefromgif ($_absolutepath);//        }//imagecopyresampled ($image _p, $image, 0, 0, 0, 0, $width, $height, $width _orig, $height _orig);//$pic = "Smalll_". substr ($_absolutepath,strrpos ($_absolutepath, '/') +1);//imagejpeg ($image _p, "imgs/comments/". $pic, +);//    }?>
View Code

PHP image Compression 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.