GD picture processing class under TP_ frame (including basic PHP image processing ideas)

Source: Internet
Author: User

<?php/** * created by phpstorm. * user: abo * date: 2016/ 1/6 0006 * time:  pm  3:37 */class imagetool{    private   $info;    private  $image;     public function __ Construct ($SRC) {         $info =getimagesize ($SRC);          $this->info=array (              ' width ' = $info [0],              ' height ' = $info [1],             ' type ' = >image_type_to_extension ($info [2],false],              ' MIME ' = $info [' MIME ']        );          $fun = "imagecreatefrom{$this->info[' type '} ";         $this->image= $fun ($SRC) ;     }    public function getimage () {         return  $this->image;    }     Public function getinfo () {        return  $this->info ;    }    /**     *  image Compression       *  @param   $width      *  @param   $height       */    public function thumb ($width, $height) {          $image _thumb=imagecreatetruecolor ($width, $height);         imagecopyresampled ($image _thumb, $this->image,0,0,0,0, $width, $height, $this->info[ ' Width '], $this->info[' heIght '])         imagedestroy ($this->image);          $this->image= $image _thumb;    }    /**      *  font watermark (default left corner)      *  @param   $fontfile   Font files consolaz.ttf     *  @param   $text   watermark content       */    public function fontmark ($fontfile, $text) {         //Red Green blue = white +50 transparency font          $col = Imagecolorallocatealpha ($this->image, 255, 255, 255, 50);           //Picture Font Composition-parameters: image, font size, deflection angle, transverse offset, portrait offset, color, font file, content          imagettftext ($this->image, 50, 0, 40,  $this->info[' height ']-50,   $col,  $fontfile,  $text);     }    /**     *  Image Watermark       *  @param   $water   watermark image      *  @param   $waterInfo   Watermark Picture Information      */    public function imagemark ($water, $ Waterinfo) {        imagecopymerge ($this->image, $water, 20,30,0,0,$ waterinfo[' width ', $waterInfo [' Height '],20);         /* image Synthesis-parameters: Target picture, Watermark picture, transverse offset, vertical offset,          * watermark picture x at start copy, watermark image y start copy,          * watermark Picture X at the end of the copy, Watermark image y at the end of the copy, Watermark image transparency.          */         Imagedestroy ($water);     }    public function showinhtml () {         header ("Content-type:".$this->info[' MIME ']);         $funs = "image{$this->info[' type '}";          $funs ($this->image);    }     /**     *  Save pictures      *  @param  $ newname  Save file name      */    public function saveimage ( $newName) {         $funs = "image{$this->info[' type ']}";          $funs ($this->image, "$newName.". $this->info[' type ']);//Save Picture     }    public function __ Destruct () {        imagedestroy ($this->image);     }}


This article from the "from the More" blog, reproduced please contact the author!

GD picture processing class under TP_ frame (including basic PHP image processing ideas)

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.