CI框架入門之MVC簡單示例
733
2024-01-20
本文實例講述了php實現(xiàn)水印文字和縮略圖的方法。分享給大家供大家參考,具體如下:
<?php $im = 'xiatian.jpg'; $im2 = 'winter3.jpg'; $img = getImage($im); $bimg = getImage($im2); //$image = getimagesize($im); //print_r($image); //Array ( [0] => 150 width /*[1] => 150 height [2] => 3 圖片類型 [3] => width="150" height="150" [bits] => 8 [mime] => image/png )*/ //圖片復(fù)制組合------$bimg---- imagecopy($bimg, $img, 300, 4, 0, 0, getWidth($im),getHeight($im)); //加水印文字 $color = imagecolorallocate($bimg,255, 255, 0); $str = "中國"; $str = mb_convert_encoding($str, "html-entities","utf-8"); imagettftext($bimg, 42, 0, rand(20,getWidth($im2)-100), rand(40,getHeight($im2)), $color, 'MSYH.TTF', $str); //剪切,重新生成縮略圖 $new = imagecreatetruecolor(50, 50); imagecopyresized($new, $bimg, 0, 0, 0, 0, 50, 50, getWidth($im2), getHeight($im2)); //輸出到瀏覽器 header("Content-Type: image/jpeg"); //如果為png圖片也可正常顯示,瀏覽器負責(zé)正確解析 imagejpeg($new); //生成大圖,小圖 imagejpeg($new,'small.jpg'); imagejpeg($bimg,'big.jpg'); function getImage($img_file) { $image = getimagesize($img_file); //判斷是那種圖片類型 switch($image[2]) { case 1: $img = @imagecreatefromgif($img_file); break; case 2: $img = @imagecreatefromjpeg($img_file); break; case 3: $img = @imagecreatefrompng($img_file); break; } return $img; } function getWidth($img_file) { $image = getimagesize($img_file); return $image[0]; } function getHeight($img_file) { $image = getimagesize($img_file); return $image[1]; } ?>
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP圖形與圖片操作技巧匯總》、《PHP基本語法入門教程》、《PHP運算與運算符用法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設(shè)計有所幫助。
#免責(zé)聲明#
本站[綠夏技術(shù)導(dǎo)航]提供的一切軟件、教程和內(nèi)容信息僅限用于學(xué)習(xí)和研究目的;不得將上述內(nèi)容用于商業(yè)或者非法用途,否則,一切后果請用戶自負。本站信息來自網(wǎng)絡(luò)收集整理,版權(quán)爭議與本站無關(guān)。您必須在下載后的24個小時之內(nèi),從您的電腦或手機中徹底刪除上述內(nèi)容。如果您喜歡該程序或內(nèi)容,請支持正版,購買注冊,得到更好的正版服務(wù)。我們非常重視版權(quán)問題,如有侵權(quán)請郵件[admin@lxwl520.com]與我們聯(lián)系進行刪除處理。敬請諒解!