PHP映像操作類

來源:互聯網
上載者:User

標籤:iam   text   tracking   ade   開啟   data-   data   des   height   

基於已給出的各種映像操作方法,這裡我總結出了PHP映像操作的一個類,包含給映像加入文字浮水印、映像浮水印和壓縮圖片。

讀者可自行加入功能。

<?

phpclass Image {private $info;private $type;private $iamge;/*** 開啟圖片,寫入記憶體***/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);}//縮圖public function thumb($width, $height){$image_thumb = imagecreatetruecolor($width, $height);imagecopyresampled($image_thumb, $this->image, 0, 0, 0, 0, $width, $height, $this->info[0], $this->info[1]);imagedestroy($this->image);$this->image = $image_thumb;}//文字浮水印public function fontMark($content, $fontUrl, $size, $color, $locate=array('x'=>0,'y'=>0), $angle=0){$color = imagecolorallocatealpha($this->image, $color[0], $color[1], $color[2], $color[3]);imagettftext($this->image, $size, $angle, $locate['x'], $locate['y'], $color, $fontUrl, $content);}//圖片浮水印public function imageMark($src,$locate,$alpha){$info2 = getimagesize($src);$type2 = image_type_to_extension($info2[2],false);$fun2 = "imagecreatefrom".$type2;$water = $fun2($src);imagecopymerge($this->image, $water, $locate['x'], $locate['y'], 0, 0, $info2[0], $info2[1], $alpha);imagedestroy($water);}//在瀏覽器中顯示public function show(){header("Content-type:".$this->info['mime']);$fun = "image".$this->type;$fun($this->image);}//儲存為檔案public function save($newname){$fun = "image".$this->type;$fun($this->image, $newname.'.'.$this->type);}public function __destruct(){imagedestroy($this->image);}}




PHP映像操作類

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.