µ±Ç°Î»Ö㺠´úÂëÃÔ >> PHP >> phpͼƬˮӡƽÌí£¬Ñ¹Ëõ£¬¼ôÇеķâ×°Àà
  Ïêϸ½â¾ö·½°¸

phpͼƬˮӡƽÌí£¬Ñ¹Ëõ£¬¼ôÇеķâ×°Àà

Èȶȣº87   ·¢²¼Ê±¼ä£º2016-04-28 17:05:14.0
phpͼƬˮӡÌí¼Ó£¬Ñ¹Ëõ£¬¼ôÇеķâ×°Àà

¡¡¡¡php¶ÔͼƬÎļþµÄ²Ù×÷Ö÷ÒªÊÇÀûÓÃGD¿âÀ©Õ¹¡£µ±ÎÒÃÇÆµ·±ÀûÓÃphp¶ÔͼƬ½øÐвÙ×÷ʱ£¬»á×ÔÈ»·â×°ºÜ¶àº¯Êý£¬·ñÔò»áд̫¶àÖØ¸´µÄ´úÂë¡£µ±Óкܶà¶ÔͼƬµÄÏà¹Øº¯ÊýµÄʱºò£¬ÎÒÃÇ¿ÉÒÔ¿¼Âǽ«ÕâЩº¯ÊýÒ²ÕûÀíһϣ¬Òò¶ø¾ÍÓÐÁË·â×°³ÉÀàµÄÏë·¨¡£

¡¡¡¡²Ù×÷ͼƬÖ÷ÒªÀú¾­Ëĸö²½Ö裺

  1. ´ò¿ªÍ¼Æ¬
  2. ²Ù×÷ͼƬ
  3. Êä³öͼƬ
  4. Ïú»ÙͼƬ

¡¡¡¡1,3,4Èý¸ö²½Öèÿ´Î¶¼ÒªÐ´£¬Ã¿´ÎÓÖ¶¼²î²»¶à¡£ÕæÕýÐèÒª±äͨµÄÖ»ÓвÙ×÷ͼƬµÄÕâÒ»²½ÖèÁË¡£²Ù×÷ͼƬÓÖÍùÍùͨ¹ý1»ò¶à¸öÖ÷ÒªµÄGDº¯ÊýÀ´Íê³É¡£

¡¡¡¡±¾ÎÄ·â×°ÀàÀïÃæµÄËÄÖÖ·½·¨£¬ÎÄ×Öˮӡ£¨imagettftext()£©£¬Í¼Æ¬Ë®Ó¡£¨imagecopymerge()£©£¬Í¼Æ¬Ñ¹Ëõ£¬Í¼Æ¬¼ôÇÐ(imagecopyresampled())£¬ÆäÓàµÄ³£ÓÃGDº¯Êý±ã²»×¸Êö¡£Ö±½ÓÉÏ´úÂ룺

<?php class Image{        private $info;    private $image;    public $type;    public function __construct($src)    {        $this->info=getimagesize($src);        $this->type=image_type_to_extension($this->info['2'],false);        $fun="imagecreatefrom{$this->type}";        $this->image=$fun($src);    }    /**     * ÎÄ×Öˮӡ     * @param  [type]  $font     ×ÖÌå     * @param  [type]  $content  ÄÚÈÝ     * @param  [type]  $size     ÎÄ×Ö´óС     * @param  [type]  $col      ÎÄ×ÖÑÕÉ«£¨ËÄÔªÊý×飩     * @param  array   $location λÖà      * @param  integer $angle    Çãб½Ç¶È     * @return [type]                */    public function fontMark($font,$content,$size,$col,$location,$angle=0){        $col=imagecolorallocatealpha($this->image, $col['0'], $col['1'], $col['2'],$col['3']);        imagettftext($this->image, $size, $angle, $location['0'], $location['1'], $col,$font,$content);    }        /**     * ͼƬˮӡ     * @param  [type] $imageMark ˮӡͼƬµØÖ·     * @param  [type] $dst       ˮӡͼƬÔÚԭͼƬÖеÄλÖà     * @param  [type] $pct       ͸Ã÷¶È     * @return [type]                 */    public function imageMark($imageMark,$dst,$pct){        $info2=getimagesize($imageMark);        $type=image_type_to_extension($info2['2'],false);        $func2="imagecreatefrom".$type;        $water=$func2($imageMark);        imagecopymerge($this->image, $water, $dst[0], $dst[1], 0, 0, $info2['0'], $info2['1'], $pct);        imagedestroy($water);    }    /**     * ѹËõͼƬ     * @param  [type] $thumbSize ѹËõͼƬ´óС     * @return [type]            [description]     */    public function thumb($thumbSize){        $imageThumb=imagecreatetruecolor($thumbSize[0], $thumbSize[1]);                imagecopyresampled($imageThumb, $this->image, 0, 0, 0, 0, $thumbSize[0], $thumbSize[1], $this->info['0'], $this->info['1']);        imagedestroy($this->image);        $this->image=$imageThumb;    }    /**    * ²Ã¼ôͼƬ     * @param  [type] $cutSize  ²Ã¼ô´óС     * @param  [type] $location ²Ã¼ôλÖà     * @return [type]           [description]     */     public function cut($cutSize,$location){         $imageCut=imagecreatetruecolor($cutSize[0],$cutSize[1]);         imagecopyresampled($imageCut, $this->image, 0, 0, $location[0], $location[1],$cutSize[0],$cutSize[1],$cutSize[0],$cutSize[1]);         imagedestroy($this->image);         $this->image=$imageCut;     }    /**     * Õ¹ÏÖͼƬ     * @return [type] [description]     */    public function show(){        header("content-type:".$this->info['mime']);        $funn="image".$this->type;        $funn($this->image);    }    /**     * ±£´æÍ¼Æ¬ * @param  [type] $newname ÐÂͼƬÃû * @return [type]          [description] */     public function save($newname){         header("content-type:".$this->info['mime']);         $funn="image".$this->type;         $funn($this->image,$newname.'.'.$this->type);     }     public function __destruct(){         imagedestroy($this->image);     } } ?>

¡¡¡¡Èç¹û»¹ÐèÒªÆäËû²Ù×÷£¬Ö»ÐèÒªÔÙÍùÕâ¸öÀàÀïÃæÌí¼Ó¾ÍºÃÀ²~~

  Ïà¹Ø½â¾ö·½°¸