PHP Package GD Library

Source: Internet
Author: User
PHP Package GD Library

Using the SAE version of thinkphp on the local and the SAE can not implement thumbnails, thumbnails are mainly used on the waterfall stream above, or an image 2 3 M, too slow, they encapsulated a, laughed at!


     class Thumb{    //Set the maximum width to use and display in the editor    Private  $max _width=NULL;Private  $file _name=NULL;Private  $water _name=NULL;//Get file name and picture width     Public  function __construct($max _widht,$file _name,$water _name)  {        $this->max_width =$max _widht;$this->file_name =$file _name;$this->water_name =$water _name; } Public  function create_image(){        //access to Ori picture information        List($width,$height,$type) = GetImageSize ($this->file_name);compression is required when the original picture is greater than the maximum width required        if($width>$this->max_width) {//Get picture compression percentage            $per=$this->max_width/$width;$new _width=$width*$per;$new _height=$height*$per; }Else{$new _height=$height;$new _width=$width; }//Create a true color image        $image _p= Imagecreatetruecolor ($new _width,$new _height-Ten);$image=$this->image_obj ($type,$this->file_name); Imagecopyresampled ($image _p,$image,0,0,0,0,$new _width,$new _height,$width,$height);$this->image_dump ($type,$image _p,$this->file_name);$this->water (); }/ * * RAW image watermark *    Private  function water(){        $water _name=$this->water_name;$dist _name=$this->file_name;List($dist _width,$dist _height,$type) = GetImageSize ($dist _name);$dist _im=$this->image_obj ($type,$this->file_name);$water _name="D:/xampps/htdocs/buyingfeiblog/1/app/modules/admin/tpl/public/images/water.png";List($w _width,$w _height) = GetImageSize ($water _name);//Get image watermark Information        $water _src= Imagecreatefrompng ($water _name);//Set picture watermark position in lower right corner        $x= ($dist _width-$w _width) /4*3;$y=($dist _height-$w _height) /4*3;if(Imagecopy ($dist _im,$water _src,$x,$y,0,0,$w _width,$w _height) {Imagepng ($dist _im,$dist _name);Echo "Success"; }Else{Echo "Error"; }    }//Generate picture type, create different picture keep picture original type does not change    Private  function image_dump($type,$image _p,$filename){         Switch($type){ Case 1: Imagegif ($image _p,$filename);$dis _im= Imagecreatefromgif (file_name); Break; Case 2: imagejpeg ($image _p,$this->file_name);$dis _im= Imagecreatefromjpeg (file_name); Break; Case 3: Imagepng ($image _p, file_name);$dis _im= Imagecreatefrompng (file_name); Break;default:        }    }//Depending on the picture, generate different resource objects    Private  function image_obj($type,$filename){         Switch($type){//1 = gif,2 = jpg,3 = PNG,             Case 1:$image= Imagecreatefromgif ($filename); Break; Case 2:$image= Imagecreatefromjpeg ($filename); Break; Case 3:$image= Imagecreatefrompng ($filename); Break;default:        }return $image; }}$thumb=NewThumb (725,"D:/xampps/htdocs/test/test.jpg");$thumb->create_image ();//create_image?>

It's so simple,
It mainly includes generating true color graphs,
Create a drawing object resource
Images to be merged, ok!

  • 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.