<pre id="ubcbz"></pre>
      \n

      Your image has been saved!<\/h1>\n \"PHP給圖片添加水印.jpg\" alt=\"\" \/>\n <\/body>\n <\/html>\n<?php \n}\nelse\n{\n?>\n \n \n Here is your pic!<\/title>\n <\/head>\n <body> <h1><a href="http://ipnx.cn/">亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱</a></h1>\n <h1>So how does it feel to be famous?<\/h1>\n <p>Here is the picture you just uploaded to your servers:<\/p>\n <!--<img src=\"images\/<?php echo $imagename;? alt=\"PHP給圖片添加水印 壓縮 剪切的封裝類_PHP\" >\" alt=\"\" style=\"max-width:90%\" \/>-->\n <\/body>\n <\/html>\n <?php\n if($_POST['submit'] == 'Upload')\n {\n $imagename = 'images\/'.$image_id.'.jpg';\n }\n else\n {\n $imagename = 'image_effect.php?id='.$image_id.'&e='.$_POST['effect'];\n if(isset($_POST['emb_caption']))\n {\n $imagename .= '&capt='.urlencode($image_caption);\n }\n if(isset($_POST['emb_logo']))\n {\n $imagename .= '&logo=1';\n }\n }\n ?>\n <img src=\"<?php echo $imagename;? alt=\"PHP給圖片添加水印 壓縮 剪切的封裝類_PHP\" >\" style=\"max-width:90%\" alt=\"\" \/>\n <table>\n <tr>\n <td>Image save as:<\/td>\n <td><?php $image_id?><\/td>\n <\/tr>\n <tr>\n <td>Height:<\/td>\n <td><?php echo $height;?><\/td>\n <\/tr>\n <tr>\n <td>Widht:<\/td>\n <td><?php echo $width;?><\/td>\n <\/tr>\n <tr>\n <td>Upload date:<\/td>\n <td><?php echo $image_date;?><\/td>\n <\/tr>\n <\/table>\n <p>You may apply a special effect to your image from the list of option below.\n Note:saving an image with any of the filters applied <em>can be undone<\/em>\n <\/p>\n <form action=\"<?php echo $_SERVER['PHP_SELF'];?>\" method=\"post\">\n <div>\n <input type=\"hidden\" name=\"id\" value=\"<?php echo $image_id;?>\"\/>\n Filter:<select name=\"effect\" id=\"\">\n <option value=\"-1\">None<\/option>\n <?php \n echo '<option value=\"'.IMG_FILTER_GRAYSCALE.'\" ';\n if(isset($_POST['effect']) && $_POST['effect'] == IMG_FILTER_GRAYSCALE)\n {\n echo 'selected=\"selected\"';\n }\n echo ' >Black and white<\/option>';\n echo '<option value=\"'.IMG_FILTER_GAUSSIAN_BLUR.'\"';\n if(isset($_POST['effect']) && $_POST['effect'] == IMG_FILTER_GAUSSIAN_BLUR)\n {\n echo ' selected=\"selected\"';\n }\n echo '>Blur<\/option>';\n echo '<option value=\"'.IMG_FILTER_EMBOSS.'\"';\n if(isset($_POST['effect']) && $_POST['effect'] == IMG_FILTER_EMBOSS)\n {\n echo 'selected=\"selected\"';\n }\n echo '>Emboss<\/option>';\n echo '<option value=\"'.IMG_FILTER_NEGATE.'\"';\n if(isset($_POST['effect']) && $_POST['effect'] == IMG_FILTER_NEGATE)\n {\n echo 'selected=\"selected\"';\n }\n echo '>Negative<\/option>';\n ?>\n <\/select><br \/>\n <?php \n echo '<input type=\"checkbox\" name=\"emb_caption\"';\n if(isset($_POST['emb_caption']))\n {\n echo ' checked=\"checked\"';\n }\n echo ' \/>Embed caption in image?';\n echo '<br \/>';\n \/\/添加水印選項\n echo '<input type=\"checkbox\" name=\"emb_logo\" ';\n if(isset($_POST['emb_logo']))\n {\n echo 'checked=\"checked\"';\n }\n echo ' \/>Embed watermarked logo in image?';\n ?>\n <input type=\"submit\" value=\"Preview\" name=\"submit\" \/><br \/><br \/>\n <input type=\"submit\" value=\"Save\" name=\"submit\" \/>\n <\/div>\n <\/form>\n<?php \n}\n?><\/pre>\n<\/p>\n<p>這里面主要是添加水印選項,如果選中添加水印則將logo.png作為水印圖片和原來的圖片合并在一起。<\/p>\n<p>在預(yù)覽文件中添加了對應(yīng)的邏輯,代碼如下:<\/p>\n<p><\/p>\n<p>\n<pre class='brush:php;toolbar:false;'>\n<?php \n$dir = 'D:\\Serious\\phpdev\\test\\images';\n\/\/設(shè)置環(huán)境變量\nputenv('GDFONTPATH='.'C:\\Windows\\Fonts');\n$font = \"arial\";\nif(isset($_GET['id']) && ctype_digit($_GET['id']) && file_exists($dir.'\/'.$_GET['id'].'.jpg'))\n{\n $image = imagecreatefromjpeg($dir.'\/'.$_GET['id'].'.jpg');\n}\nelse\n{\n die('invalid image specified');\n}\n$effect = (isset($_GET['e'])) ? $_GET['e'] : -1;\nswitch($effect)\n{\n case IMG_FILTER_NEGATE:\n imagefilter($image , IMG_FILTER_NEGATE);\n break;\n case IMG_FILTER_GRAYSCALE:\n imagefilter($image , IMG_FILTER_GRAYSCALE);\n break; \n case IMG_FILTER_EMBOSS:\n imagefilter($image , IMG_FILTER_EMBOSS);\n break; \n case IMG_FILTER_GAUSSIAN_BLUR:\n imagefilter($image , IMG_FILTER_GAUSSIAN_BLUR);\n break; \n}\nif(isset($_GET['capt']))\n{\n \/\/echo $_GET['capt'];\n imagettftext($image, 12, 0, 20, 20, 0, $font, $_GET['capt']);\n}\nif(isset($_GET['logo']))\n{\n list($widht , $height) = getimagesize($dir.'\/'.$_GET['id'].'.jpg');\n list($wmk_width , $wmk_height) = getimagesize('images\/logo.png');\n $x = ($widht-$wmk_width) \/ 2;\n $y = ($height-$wmk_height) \/ 2;\n $wmk = imagecreatefrompng('images\/logo.png');\n imagecopymerge($image , $wmk , $x , $y , 0 , 0 , $wmk_width , $wmk_height , 20);\n imagedestroy($wmk);\n}\nheader('Content-Type:image\/jpeg');\nimagejpeg($image , '' , 100);\n?><\/pre>\n<\/p>\n<p>最后上傳的水印圖片效果如下:<\/p>\n<p style=\"text-align: center\"><img alt=\"\" src=\"http:\/\/img.bitscn.com\/upimg\/allimg\/c150827\/144064505245310-12645.jpg\" \/><\/p>\n<p>注意主要的邏輯就是通過 <strong>imagecopymerge() <\/strong>方法把兩個圖片合并在一起造成水印效果。來看看這個方法的方法原型和參數(shù):<\/p>\n<p>\n<pre class='brush:php;toolbar:false;'>\nbool imagecopymerge ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int$src_x , int $src_y , int $src_w , int $src_h , int $pct )<\/pre>\n<\/p>\n<p><\/p>\n<p>將 src_im 圖像中坐標(biāo)從 src_x,src_y 開始,寬度為 src_w,高度為 src_h 的一部分拷貝到 dst_im 圖像中坐標(biāo)為 dst_x 和 dst_y 的位置上。兩圖像將根據(jù) pct 來決定合并程度,其值范圍從 0 到 100。當(dāng) pct = 0 時,實際上什么也沒做,當(dāng)為 100 時對于調(diào)色板圖像本函數(shù)和 imagecopy() 完全一樣,它對真彩色圖像實現(xiàn)了 alpha 透明。<br>\n<\/p>\n<p>以上內(nèi)容是本文介紹PHP給圖片添加水印 壓縮 剪切的封裝類的全部內(nèi)容,希望大家對本文介紹感興趣。<\/p>\n "} </script> <meta http-equiv="Cache-Control" content="no-transform" /> <meta http-equiv="Cache-Control" content="no-siteapp" /> <script>var V_PATH="/";window.onerror=function(){ return true; };</script> </head> <body data-commit-time="2023-12-28T14:50:12+08:00" class="editor_body body2_2"> <link rel="stylesheet" type="text/css" href="/static/csshw/stylehw.css"> <header> <div id="wjcelcm34c" class="head"> <div id="wjcelcm34c" class="haed_left"> <div id="wjcelcm34c" class="haed_logo"> <a href="http://ipnx.cn/zh-tw/" title="" class="haed_logo_a"> <img src="/static/imghw/logo.png" alt="" class="haed_logoimg"> </a> </div> <div id="wjcelcm34c" class="head_nav"> <div id="wjcelcm34c" class="head_navs"> <a href="javascript:;" title="社群" class="head_nava head_nava-template1">社群</a> <div class="wjcelcm34c" id="dropdown-template1" style="display: none;"> <div id="wjcelcm34c" class="languagechoose"> <a href="http://ipnx.cn/zh-tw/article.html" title="文章" class="languagechoosea on">文章</a> <a href="http://ipnx.cn/zh-tw/faq/zt" title="合集" class="languagechoosea">合集</a> <a href="http://ipnx.cn/zh-tw/wenda.html" title="問答" class="languagechoosea">問答</a> </div> </div> </div> <div id="wjcelcm34c" class="head_navs"> <a href="javascript:;" title="學(xué)習(xí)" class="head_nava head_nava-template1_1">學(xué)習(xí)</a> <div class="wjcelcm34c" id="dropdown-template1_1" style="display: none;"> <div id="wjcelcm34c" class="languagechoose"> <a href="http://ipnx.cn/zh-tw/course.html" title="課程" class="languagechoosea on">課程</a> <a href="http://ipnx.cn/zh-tw/dic/" title="程式設(shè)計字典" class="languagechoosea">程式設(shè)計字典</a> </div> </div> </div> <div id="wjcelcm34c" class="head_navs"> <a href="javascript:;" title="工具庫" class="head_nava head_nava-template1_2">工具庫</a> <div class="wjcelcm34c" id="dropdown-template1_2" style="display: none;"> <div id="wjcelcm34c" class="languagechoose"> <a href="http://ipnx.cn/zh-tw/toolset/development-tools" title="開發(fā)工具" class="languagechoosea on">開發(fā)工具</a> <a href="http://ipnx.cn/zh-tw/toolset/website-source-code" title="網(wǎng)站源碼" class="languagechoosea">網(wǎng)站源碼</a> <a href="http://ipnx.cn/zh-tw/toolset/php-libraries" title="PHP 函式庫" class="languagechoosea">PHP 函式庫</a> <a href="http://ipnx.cn/zh-tw/toolset/js-special-effects" title="JS特效" class="languagechoosea on">JS特效</a> <a href="http://ipnx.cn/zh-tw/toolset/website-materials" title="網(wǎng)站素材" class="languagechoosea on">網(wǎng)站素材</a> <a href="http://ipnx.cn/zh-tw/toolset/extension-plug-ins" title="擴充插件" class="languagechoosea on">擴充插件</a> </div> </div> </div> <div id="wjcelcm34c" class="head_navs"> <a href="http://ipnx.cn/zh-tw/ai" title="AI工具" class="head_nava head_nava-template1_3">AI工具</a> </div> <div id="wjcelcm34c" class="head_navs"> <a href="javascript:;" title="休閒" class="head_nava head_nava-template1_3">休閒</a> <div class="wjcelcm34c" id="dropdown-template1_3" style="display: none;"> <div id="wjcelcm34c" class="languagechoose"> <a href="http://ipnx.cn/zh-tw/game" title="遊戲下載" class="languagechoosea on">遊戲下載</a> <a href="http://ipnx.cn/zh-tw/mobile-game-tutorial/" title="遊戲教程" class="languagechoosea">遊戲教程</a> </div> </div> </div> </div> </div> <div id="wjcelcm34c" class="head_search"> <input id="key_words" onkeydown="if (event.keyCode == 13) searchs('zh-tw')" class="search-input" type="text" autocomplete="off" name="keywords" required="required" placeholder="Block,address,transaction,news" value=""> <a href="javascript:;" title="搜尋" onclick="searchs('zh-tw')"><img src="/static/imghw/find.png" alt="搜尋"></a> </div> <div id="wjcelcm34c" class="head_right"> <div id="wjcelcm34c" class="haed_language"> <a href="javascript:;" class="layui-btn haed_language_btn">繁體中文<i class="layui-icon layui-icon-triangle-d"></i></a> <div class="wjcelcm34c" id="dropdown-template" style="display: none;"> <div id="wjcelcm34c" class="languagechoose"> <a href="javascript:setlang('zh-cn');" title="簡體中文" class="languagechoosea">簡體中文</a> <a href="javascript:setlang('en');" title="English" class="languagechoosea">English</a> <a href="javascript:;" title="繁體中文" class="languagechoosea">繁體中文</a> <a href="javascript:setlang('ja');" title="日本語" class="languagechoosea">日本語</a> <a href="javascript:setlang('ko');" title="???" class="languagechoosea">???</a> <a href="javascript:setlang('ms');" title="Melayu" class="languagechoosea">Melayu</a> <a href="javascript:setlang('fr');" title="Fran?ais" class="languagechoosea">Fran?ais</a> <a href="javascript:setlang('de');" title="Deutsch" class="languagechoosea">Deutsch</a> </div> </div> </div> <span id="wjcelcm34c" class="head_right_line"></span> <div style="display: block;" id="login" class="haed_login "> <a href="javascript:;" title="Login" class="haed_logina ">Login</a> </div> <div style="display: block;" id="reg" class="head_signup login"> <a href="javascript:;" title="singup" class="head_signupa">singup</a> </div> </div> </div> </header> <main> <div id="wjcelcm34c" class="Article_Details_main"> <div id="wjcelcm34c" class="Article_Details_main1"> <div id="wjcelcm34c" class="Article_Details_main1M"> <div id="wjcelcm34c" class="phpgenera_Details_mainL1"> <a href="http://ipnx.cn/zh-tw/" title="首頁" class="phpgenera_Details_mainL1a">首頁</a> <img src="/static/imghw/top_right.png" alt="" /> <a href="http://ipnx.cn/zh-tw/be/" class="phpgenera_Details_mainL1a">後端開發(fā)</a> <img src="/static/imghw/top_right.png" alt="" /> <a href="http://ipnx.cn/zh-tw/php-weizijiaocheng.html" class="phpgenera_Details_mainL1a">php教程</a> <img src="/static/imghw/top_right.png" alt="" /> <span>PHP給圖片添加水印 壓縮 剪切的封裝類_PHP</span> </div> <div id="wjcelcm34c" class="Articlelist_txts"> <div id="wjcelcm34c" class="Articlelist_txts_info"> <h1 class="Articlelist_txts_title">PHP給圖片添加水印 壓縮 剪切的封裝類_PHP</h1> <div id="wjcelcm34c" class="Articlelist_txts_info_head"> <div id="wjcelcm34c" class="author_info"> <a href="http://ipnx.cn/zh-tw/member/887227.html" class="author_avatar"> <img class="lazy" data-src="https://img.php.cn/upload/avatar/000/887/227/63bb7851c9547215.jpg" src="/static/imghw/default1.png" alt="WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB"> </a> <div id="wjcelcm34c" class="author_detail"> <a href="http://ipnx.cn/zh-tw/member/887227.html" class="author_name">WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB</a> </div> </div> </div> <span id="wjcelcm34c" class="Articlelist_txts_time">May 30, 2016 am 08:47 AM</span> <div id="wjcelcm34c" class="Articlelist_txts_infos"> <span id="wjcelcm34c" class="Articlelist_txts_infoss on">添加浮水印</span> </div> </div> </div> <hr /> <div id="wjcelcm34c" class="article_main php-article"> <div id="wjcelcm34c" class="article-list-left detail-content-wrap content"> <ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-5902227090019525" data-ad-slot="3461856641"> </ins> <p>給圖片添加水印,其實就是把原來的圖片和水印添加在一起,下面小編把最近整理的資料分享給大家。</p> <p>php對圖片文件的操作主要是利用GD庫擴展。當(dāng)我們頻繁利用php對圖片進行操作時,會自然封裝很多函數(shù),否則會寫太多重復(fù)的代碼。當(dāng)有很多對圖片的相關(guān)函數(shù)的時候,我們可以考慮將這些函數(shù)也整理一下,因而就有了封裝成類的想法。</p> <p> <strong> 操作圖片主要歷經(jīng)四個步驟:</strong></p> <p>??????? 第一步:打開圖片</p> <p>??????? 第二步:操作圖片<br> </p> <p>??????? 第三步:輸出圖片<br> </p> <p>??????? 第四步:銷毀圖片<br> </p> <p>  1,3,4三個步驟每次都要寫,每次又都差不多。真正需要變通的只有操作圖片的這一步驟了。操作圖片又往往通過1或多個主要的GD函數(shù)來完成。</p> <p>  <strong>本文封裝類里面的四種方法,文字水印(imagettftext()),圖片水印(imagecopymerge()),圖片壓縮,圖片剪切(imagecopyresampled()),其余的常用GD函數(shù)便不贅述。</strong></p> <p>直接上代碼:</p> <p> <pre class='brush:php;toolbar:false;'> <&#63;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 內(nèi)容 * @param [type] $size 文字大小 * @param [type] $col 文字顏色(四元數(shù)組) * @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; } /** * 展現(xiàn)圖片 * @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); } } &#63;></pre> </p> <p>如果還需要其他操作,只需要再往這個類里面添加就好啦~~</p> <p><span style="color: #ff0000">給圖片添加水印代碼:</span></p> <p>先看文件check_image_addwatermark.php代碼</p> <p> <pre class='brush:php;toolbar:false;'> <&#63;php //修改圖片效果 $db = mysql_connect('localhost','root','Ctrip07185419') or die('can not connect to database'); mysql_select_db('moviesite',$db) or die(mysql_error($db)); //上傳文件的路徑 $dir = 'D:\Serious\phpdev\test\images'; //設(shè)置環(huán)境變量 putenv('GDFONTPATH='.'C:\Windows\Fonts'); $font = "arial"; //upload_image.php頁面?zhèn)鬟f過來的參數(shù),如果是上傳圖片 if($_POST['submit'] == 'Upload') { if($_FILES['uploadfile']['error'] != UPLOAD_ERR_OK) { switch($_FILES['uploadfile']['error']) { case UPLOAD_ERR_INI_SIZE: die('The uploaded file exceeds the upload_max_filesize directive'); break; case UPLOAD_ERR_FORM_SIZE: die('The upload file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'); break; case UPLOAD_ERR_PARTIAL: die('The uploaded file was only partially uploaded'); break; case UPLOAD_ERR_NO_FILE: die('No file was uploaded'); break; case UPLOAD_ERR_NO_TMP_DIR: die('The server is missing a temporary folder'); break; case UPLOAD_ERR_CANT_WRITE: die('The server fail to write the uploaded file to the disk'); break; case UPLOAD_ERR_EXTENSION: die('The upload stopped by extension'); break; } } $image_caption = $_POST['caption']; $image_username = $_POST['username']; $image_date = date('Y-m-d'); list($width,$height,$type,$attr) = getimagesize($_FILES['uploadfile']['tmp_name']); $error = 'The file you upload is not a supported filetype'; switch($type) { case IMAGETYPE_GIF: $image = imagecreatefromgif($_FILES['uploadfile']['tmp_name']) or die($error); break; case IMAGETYPE_JPEG: $image = imagecreatefromjpeg($_FILES['uploadfile']['tmp_name']) or die($error); break; case IMAGETYPE_PNG: $image = imagecreatefrompng($_FILES['uploadfile']['tmp_name']) or die($error); break; default: break; } $query = 'insert into images(image_caption,image_username,image_date) values("'.$image_caption.'" , "'.$image_username.'","'.$image_date.'")'; $result = mysql_query($query,$db) or die(mysql_error($db)); $last_id = mysql_insert_id(); // $imagename = $last_id.'.jpg'; // imagejpeg($image,$dir.'/'.$imagename); // imagedestroy($image); $image_id = $last_id; imagejpeg($image , $dir.'/'.$image_id.'.jpg'); imagedestroy($image); } else //如果圖片已經(jīng)上傳,則從數(shù)據(jù)庫中取圖片名字 { $query = 'select image_id,image_caption,image_username,image_date from images where image_id='.$_POST['id']; $result = mysql_query($query,$db) or die(mysql_error($db)); extract(mysql_fetch_assoc($result)); list($width,$height,$type,$attr) = getimagesize($dir.'/'.$image_id.'.jpg'); } //如果是保存圖片 if($_POST['submit'] == 'Save') { if(isset($_POST['id']) && ctype_digit($_POST['id']) && file_exists($dir.'/'.$_POST['id'].'.jpg')) { $image = imagecreatefromjpeg($dir.'/'.$_POST['id'].'.jpg'); } else { die('invalid image specified'); } $effect = (isset($_POST['effect'])) &#63; $_POST['effect'] : -1; switch($effect) { case IMG_FILTER_NEGATE: imagefilter($image , IMG_FILTER_NEGATE); //將圖像中所有顏色反轉(zhuǎn) break; case IMG_FILTER_GRAYSCALE: imagefilter($image , IMG_FILTER_GRAYSCALE); //將圖像轉(zhuǎn)換為灰度的 break; case IMG_FILTER_EMBOSS: imagefilter($image , IMG_FILTER_EMBOSS); //使圖像浮雕化 break; case IMG_FILTER_GAUSSIAN_BLUR: imagefilter($image , IMG_FILTER_GAUSSIAN_BLUR); //用高斯算法模糊圖像 break; } if(isset($_POST['emb_caption'])) { imagettftext($image , 12 , 0 , 20 , 20 , 0 , $font , $image_caption); } if(isset($_POST['emb_logo'])) { //獲取水印圖片的尺寸并創(chuàng)建水印 list($wmk_width , $wmk_height) = getimagesize('images/logo.png'); $x = ($width-$wmk_width) / 2; $y = ($height-$wmk_height)/2; $wmk = imagecreatefrompng('images/logo.png'); //把水印圖片和原圖片合并在一起 imagecopymerge($image , $wmk , $x , $y , 0 , 0 , $wmk_width , $wmk_height , 20); //清除水印圖片 imagedestroy($wmk); } imagejpeg($image , $dir.'/'.$_POST['id'].'.jpg' , 100); &#63;> <html> <head> <title>Here is your pic!</title> </head> <body> <h1>Your image has been saved!</h1> <img src="/static/imghw/default1.png" data-src="http://img.bitscn.com/upimg/allimg/c150827/144064505245310-12645.jpg" class="lazy"id'];&#63; alt="PHP給圖片添加水印 壓縮 剪切的封裝類_PHP" >.jpg" alt="" /> </body> </html> <&#63;php } else { &#63;> <html> <head> <title>Here is your pic!</title> </head> <body> <h1>So how does it feel to be famous&#63;</h1> <p>Here is the picture you just uploaded to your servers:</p> <!--<img src="/static/imghw/default1.png" data-src="http://img.bitscn.com/upimg/allimg/c150827/144064505245310-12645.jpg" class="lazy" alt="" style="max-width:90%" />--> </body> </html> <&#63;php if($_POST['submit'] == 'Upload') { $imagename = 'images/'.$image_id.'.jpg'; } else { $imagename = 'image_effect.php&#63;id='.$image_id.'&e='.$_POST['effect']; if(isset($_POST['emb_caption'])) { $imagename .= '&capt='.urlencode($image_caption); } if(isset($_POST['emb_logo'])) { $imagename .= '&logo=1'; } } &#63;> <img src="/static/imghw/default1.png" data-src="http://img.bitscn.com/upimg/allimg/c150827/144064505245310-12645.jpg" class="lazy" style="max-width:90%" alt="" /> <table> <tr> <td>Image save as:</td> <td><&#63;php $image_id&#63;></td> </tr> <tr> <td>Height:</td> <td><&#63;php echo $height;&#63;></td> </tr> <tr> <td>Widht:</td> <td><&#63;php echo $width;&#63;></td> </tr> <tr> <td>Upload date:</td> <td><&#63;php echo $image_date;&#63;></td> </tr> </table> <p>You may apply a special effect to your image from the list of option below. Note:saving an image with any of the filters applied <em>can be undone</em> </p> <form action="<&#63;php echo $_SERVER['PHP_SELF'];&#63;>" method="post"> <div> <input type="hidden" name="id" value="<&#63;php echo $image_id;&#63;>"/> Filter:<select name="effect" id=""> <option value="-1">None</option> <&#63;php echo '<option value="'.IMG_FILTER_GRAYSCALE.'" '; if(isset($_POST['effect']) && $_POST['effect'] == IMG_FILTER_GRAYSCALE) { echo 'selected="selected"'; } echo ' >Black and white</option>'; echo '<option value="'.IMG_FILTER_GAUSSIAN_BLUR.'"'; if(isset($_POST['effect']) && $_POST['effect'] == IMG_FILTER_GAUSSIAN_BLUR) { echo ' selected="selected"'; } echo '>Blur</option>'; echo '<option value="'.IMG_FILTER_EMBOSS.'"'; if(isset($_POST['effect']) && $_POST['effect'] == IMG_FILTER_EMBOSS) { echo 'selected="selected"'; } echo '>Emboss</option>'; echo '<option value="'.IMG_FILTER_NEGATE.'"'; if(isset($_POST['effect']) && $_POST['effect'] == IMG_FILTER_NEGATE) { echo 'selected="selected"'; } echo '>Negative</option>'; &#63;> </select><br /> <&#63;php echo '<input type="checkbox" name="emb_caption"'; if(isset($_POST['emb_caption'])) { echo ' checked="checked"'; } echo ' />Embed caption in image&#63;'; echo '<br />'; //添加水印選項 echo '<input type="checkbox" name="emb_logo" '; if(isset($_POST['emb_logo'])) { echo 'checked="checked"'; } echo ' />Embed watermarked logo in image&#63;'; &#63;> <input type="submit" value="Preview" name="submit" /><br /><br /> <input type="submit" value="Save" name="submit" /> </div> </form> <&#63;php } &#63;></pre> </p> <p>這里面主要是添加水印選項,如果選中添加水印則將logo.png作為水印圖片和原來的圖片合并在一起。</p> <p>在預(yù)覽文件中添加了對應(yīng)的邏輯,代碼如下:</p> <p></p> <p> <pre class='brush:php;toolbar:false;'> <&#63;php $dir = 'D:\Serious\phpdev\test\images'; //設(shè)置環(huán)境變量 putenv('GDFONTPATH='.'C:\Windows\Fonts'); $font = "arial"; if(isset($_GET['id']) && ctype_digit($_GET['id']) && file_exists($dir.'/'.$_GET['id'].'.jpg')) { $image = imagecreatefromjpeg($dir.'/'.$_GET['id'].'.jpg'); } else { die('invalid image specified'); } $effect = (isset($_GET['e'])) &#63; $_GET['e'] : -1; switch($effect) { case IMG_FILTER_NEGATE: imagefilter($image , IMG_FILTER_NEGATE); break; case IMG_FILTER_GRAYSCALE: imagefilter($image , IMG_FILTER_GRAYSCALE); break; case IMG_FILTER_EMBOSS: imagefilter($image , IMG_FILTER_EMBOSS); break; case IMG_FILTER_GAUSSIAN_BLUR: imagefilter($image , IMG_FILTER_GAUSSIAN_BLUR); break; } if(isset($_GET['capt'])) { //echo $_GET['capt']; imagettftext($image, 12, 0, 20, 20, 0, $font, $_GET['capt']); } if(isset($_GET['logo'])) { list($widht , $height) = getimagesize($dir.'/'.$_GET['id'].'.jpg'); list($wmk_width , $wmk_height) = getimagesize('images/logo.png'); $x = ($widht-$wmk_width) / 2; $y = ($height-$wmk_height) / 2; $wmk = imagecreatefrompng('images/logo.png'); imagecopymerge($image , $wmk , $x , $y , 0 , 0 , $wmk_width , $wmk_height , 20); imagedestroy($wmk); } header('Content-Type:image/jpeg'); imagejpeg($image , '' , 100); &#63;></pre> </p> <p>最后上傳的水印圖片效果如下:</p> <p style="text-align: center"><img src="/static/imghw/default1.png" data-src="http://img.bitscn.com/upimg/allimg/c150827/144064505245310-12645.jpg" class="lazy" alt="" /></p> <p>注意主要的邏輯就是通過 <strong>imagecopymerge() </strong>方法把兩個圖片合并在一起造成水印效果。來看看這個方法的方法原型和參數(shù):</p> <p> <pre class='brush:php;toolbar:false;'> bool imagecopymerge ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int$src_x , int $src_y , int $src_w , int $src_h , int $pct )</pre> </p> <p></p> <p>將 src_im 圖像中坐標(biāo)從 src_x,src_y 開始,寬度為 src_w,高度為 src_h 的一部分拷貝到 dst_im 圖像中坐標(biāo)為 dst_x 和 dst_y 的位置上。兩圖像將根據(jù) pct 來決定合并程度,其值范圍從 0 到 100。當(dāng) pct = 0 時,實際上什么也沒做,當(dāng)為 100 時對于調(diào)色板圖像本函數(shù)和 imagecopy() 完全一樣,它對真彩色圖像實現(xiàn)了 alpha 透明。<br> </p> <p>以上內(nèi)容是本文介紹PHP給圖片添加水印 壓縮 剪切的封裝類的全部內(nèi)容,希望大家對本文介紹感興趣。</p> </div> </div> <div id="wjcelcm34c" class="wzconShengming_sp"> <div id="wjcelcm34c" class="bzsmdiv_sp">本網(wǎng)站聲明</div> <div>本文內(nèi)容由網(wǎng)友自願投稿,版權(quán)歸原作者所有。本站不承擔(dān)相應(yīng)的法律責(zé)任。如發(fā)現(xiàn)涉嫌抄襲或侵權(quán)的內(nèi)容,請聯(lián)絡(luò)admin@php.cn</div> </div> </div> <ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5902227090019525" data-ad-slot="2507867629"></ins> <div id="wjcelcm34c" class="AI_ToolDetails_main4sR"> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5902227090019525" data-ad-slot="3653428331" data-ad-format="auto" data-full-width-responsive="true"></ins> <!-- <div id="wjcelcm34c" class="phpgenera_Details_mainR4"> <div id="wjcelcm34c" class="phpmain1_4R_readrank"> <div id="wjcelcm34c" class="phpmain1_4R_readrank_top"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/hotarticle2.png" alt="" /> <h2>熱門文章</h2> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottom"> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms"> <a href="http://ipnx.cn/zh-tw/faq/1796832397.html" title="Grass Wonder Build Guide |烏瑪媽媽漂亮的德比" class="phpgenera_Details_mainR4_bottom_title">Grass Wonder Build Guide |烏瑪媽媽漂亮的德比</a> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms_info"> <span>3 週前</span> <span>By Jack chen</span> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms"> <a href="http://ipnx.cn/zh-tw/faq/1796833110.html" title="<??>:在森林裡99夜 - 所有徽章以及如何解鎖" class="phpgenera_Details_mainR4_bottom_title"><??>:在森林裡99夜 - 所有徽章以及如何解鎖</a> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms_info"> <span>3 週前</span> <span>By DDD</span> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms"> <a href="http://ipnx.cn/zh-tw/faq/1796831605.html" title="烏瑪?shù)姆劢z漂亮的德比橫幅日程(2025年7月)" class="phpgenera_Details_mainR4_bottom_title">烏瑪?shù)姆劢z漂亮的德比橫幅日程(2025年7月)</a> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms_info"> <span>4 週前</span> <span>By Jack chen</span> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms"> <a href="http://ipnx.cn/zh-tw/faq/1796831905.html" title="Windows安全是空白或不顯示選項" class="phpgenera_Details_mainR4_bottom_title">Windows安全是空白或不顯示選項</a> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms_info"> <span>4 週前</span> <span>By 下次還敢</span> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms"> <a href="http://ipnx.cn/zh-tw/faq/1796836699.html" title="Rimworld Odyssey溫度指南和Gravtech" class="phpgenera_Details_mainR4_bottom_title">Rimworld Odyssey溫度指南和Gravtech</a> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms_info"> <span>3 週前</span> <span>By Jack chen</span> </div> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR3_more"> <a href="http://ipnx.cn/zh-tw/article.html">顯示更多</a> </div> </div> </div> --> <div id="wjcelcm34c" class="phpgenera_Details_mainR3"> <div id="wjcelcm34c" class="phpmain1_4R_readrank"> <div id="wjcelcm34c" class="phpmain1_4R_readrank_top"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/hottools2.png" alt="" /> <h2>熱AI工具</h2> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR3_bottom"> <div id="wjcelcm34c" class="phpmain_tab2_mids_top"> <a href="http://ipnx.cn/zh-tw/ai/undress-ai-tool" title="Undress AI Tool" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173410641626608.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Undress AI Tool" /> </a> <div id="wjcelcm34c" class="phpmain_tab2_mids_info"> <a href="http://ipnx.cn/zh-tw/ai/undress-ai-tool" title="Undress AI Tool" class="phpmain_tab2_mids_title"> <h3>Undress AI Tool</h3> </a> <p>免費脫衣圖片</p> </div> </div> <div id="wjcelcm34c" class="phpmain_tab2_mids_top"> <a href="http://ipnx.cn/zh-tw/ai/undresserai-undress" title="Undresser.AI Undress" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173411540686492.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Undresser.AI Undress" /> </a> <div id="wjcelcm34c" class="phpmain_tab2_mids_info"> <a href="http://ipnx.cn/zh-tw/ai/undresserai-undress" title="Undresser.AI Undress" class="phpmain_tab2_mids_title"> <h3>Undresser.AI Undress</h3> </a> <p>人工智慧驅(qū)動的應(yīng)用程序,用於創(chuàng)建逼真的裸體照片</p> </div> </div> <div id="wjcelcm34c" class="phpmain_tab2_mids_top"> <a href="http://ipnx.cn/zh-tw/ai/ai-clothes-remover" title="AI Clothes Remover" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173411552797167.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="AI Clothes Remover" /> </a> <div id="wjcelcm34c" class="phpmain_tab2_mids_info"> <a href="http://ipnx.cn/zh-tw/ai/ai-clothes-remover" title="AI Clothes Remover" class="phpmain_tab2_mids_title"> <h3>AI Clothes Remover</h3> </a> <p>用於從照片中去除衣服的線上人工智慧工具。</p> </div> </div> <div id="wjcelcm34c" class="phpmain_tab2_mids_top"> <a href="http://ipnx.cn/zh-tw/ai/clothoffio" title="Clothoff.io" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173411529149311.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Clothoff.io" /> </a> <div id="wjcelcm34c" class="phpmain_tab2_mids_info"> <a href="http://ipnx.cn/zh-tw/ai/clothoffio" title="Clothoff.io" class="phpmain_tab2_mids_title"> <h3>Clothoff.io</h3> </a> <p>AI脫衣器</p> </div> </div> <div id="wjcelcm34c" class="phpmain_tab2_mids_top"> <a href="http://ipnx.cn/zh-tw/ai/video-swap" title="Video Face Swap" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173414504068133.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Video Face Swap" /> </a> <div id="wjcelcm34c" class="phpmain_tab2_mids_info"> <a href="http://ipnx.cn/zh-tw/ai/video-swap" title="Video Face Swap" class="phpmain_tab2_mids_title"> <h3>Video Face Swap</h3> </a> <p>使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!</p> </div> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR3_more"> <a href="http://ipnx.cn/zh-tw/ai">顯示更多</a> </div> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4"> <div id="wjcelcm34c" class="phpmain1_4R_readrank"> <div id="wjcelcm34c" class="phpmain1_4R_readrank_top"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/hotarticle2.png" alt="" /> <h2>熱門文章</h2> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottom"> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms"> <a href="http://ipnx.cn/zh-tw/faq/1796832397.html" title="Grass Wonder Build Guide |烏瑪媽媽漂亮的德比" class="phpgenera_Details_mainR4_bottom_title">Grass Wonder Build Guide |烏瑪媽媽漂亮的德比</a> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms_info"> <span>3 週前</span> <span>By Jack chen</span> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms"> <a href="http://ipnx.cn/zh-tw/faq/1796833110.html" title="<??>:在森林裡99夜 - 所有徽章以及如何解鎖" class="phpgenera_Details_mainR4_bottom_title"><??>:在森林裡99夜 - 所有徽章以及如何解鎖</a> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms_info"> <span>3 週前</span> <span>By DDD</span> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms"> <a href="http://ipnx.cn/zh-tw/faq/1796831605.html" title="烏瑪?shù)姆劢z漂亮的德比橫幅日程(2025年7月)" class="phpgenera_Details_mainR4_bottom_title">烏瑪?shù)姆劢z漂亮的德比橫幅日程(2025年7月)</a> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms_info"> <span>4 週前</span> <span>By Jack chen</span> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms"> <a href="http://ipnx.cn/zh-tw/faq/1796831905.html" title="Windows安全是空白或不顯示選項" class="phpgenera_Details_mainR4_bottom_title">Windows安全是空白或不顯示選項</a> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms_info"> <span>4 週前</span> <span>By 下次還敢</span> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms"> <a href="http://ipnx.cn/zh-tw/faq/1796836699.html" title="Rimworld Odyssey溫度指南和Gravtech" class="phpgenera_Details_mainR4_bottom_title">Rimworld Odyssey溫度指南和Gravtech</a> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms_info"> <span>3 週前</span> <span>By Jack chen</span> </div> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR3_more"> <a href="http://ipnx.cn/zh-tw/article.html">顯示更多</a> </div> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR3"> <div id="wjcelcm34c" class="phpmain1_4R_readrank"> <div id="wjcelcm34c" class="phpmain1_4R_readrank_top"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/hottools2.png" alt="" /> <h2>熱工具</h2> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR3_bottom"> <div id="wjcelcm34c" class="phpmain_tab2_mids_top"> <a href="http://ipnx.cn/zh-tw/toolset/development-tools/92" title="記事本++7.3.1" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/manual/000/000/001/58ab96f0f39f7357.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="記事本++7.3.1" /> </a> <div id="wjcelcm34c" class="phpmain_tab2_mids_info"> <a href="http://ipnx.cn/zh-tw/toolset/development-tools/92" title="記事本++7.3.1" class="phpmain_tab2_mids_title"> <h3>記事本++7.3.1</h3> </a> <p>好用且免費的程式碼編輯器</p> </div> </div> <div id="wjcelcm34c" class="phpmain_tab2_mids_top"> <a href="http://ipnx.cn/zh-tw/toolset/development-tools/93" title="SublimeText3漢化版" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/manual/000/000/001/58ab97a3baad9677.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="SublimeText3漢化版" /> </a> <div id="wjcelcm34c" class="phpmain_tab2_mids_info"> <a href="http://ipnx.cn/zh-tw/toolset/development-tools/93" title="SublimeText3漢化版" class="phpmain_tab2_mids_title"> <h3>SublimeText3漢化版</h3> </a> <p>中文版,非常好用</p> </div> </div> <div id="wjcelcm34c" class="phpmain_tab2_mids_top"> <a href="http://ipnx.cn/zh-tw/toolset/development-tools/121" title="禪工作室 13.0.1" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/manual/000/000/001/58ab97ecd1ab2670.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="禪工作室 13.0.1" /> </a> <div id="wjcelcm34c" class="phpmain_tab2_mids_info"> <a href="http://ipnx.cn/zh-tw/toolset/development-tools/121" title="禪工作室 13.0.1" class="phpmain_tab2_mids_title"> <h3>禪工作室 13.0.1</h3> </a> <p>強大的PHP整合開發(fā)環(huán)境</p> </div> </div> <div id="wjcelcm34c" class="phpmain_tab2_mids_top"> <a href="http://ipnx.cn/zh-tw/toolset/development-tools/469" title="Dreamweaver CS6" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/manual/000/000/001/58d0e0fc74683535.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="Dreamweaver CS6" /> </a> <div id="wjcelcm34c" class="phpmain_tab2_mids_info"> <a href="http://ipnx.cn/zh-tw/toolset/development-tools/469" title="Dreamweaver CS6" class="phpmain_tab2_mids_title"> <h3>Dreamweaver CS6</h3> </a> <p>視覺化網(wǎng)頁開發(fā)工具</p> </div> </div> <div id="wjcelcm34c" class="phpmain_tab2_mids_top"> <a href="http://ipnx.cn/zh-tw/toolset/development-tools/500" title="SublimeText3 Mac版" class="phpmain_tab2_mids_top_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" class="lazy" data-src="https://img.php.cn/upload/manual/000/000/001/58d34035e2757995.png?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="SublimeText3 Mac版" /> </a> <div id="wjcelcm34c" class="phpmain_tab2_mids_info"> <a href="http://ipnx.cn/zh-tw/toolset/development-tools/500" title="SublimeText3 Mac版" class="phpmain_tab2_mids_title"> <h3>SublimeText3 Mac版</h3> </a> <p>神級程式碼編輯軟體(SublimeText3)</p> </div> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR3_more"> <a href="http://ipnx.cn/zh-tw/ai">顯示更多</a> </div> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4"> <div id="wjcelcm34c" class="phpmain1_4R_readrank"> <div id="wjcelcm34c" class="phpmain1_4R_readrank_top"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/hotarticle2.png" alt="" /> <h2>熱門話題</h2> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottom"> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms"> <a href="http://ipnx.cn/zh-tw/faq/laravel-tutori" title="Laravel 教程" class="phpgenera_Details_mainR4_bottom_title">Laravel 教程</a> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms_info"> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms_infos"> <img src="/static/imghw/eyess.png" alt="" /> <span>1597</span> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms_infos"> <img src="/static/imghw/tiezi.png" alt="" /> <span>29</span> </div> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms"> <a href="http://ipnx.cn/zh-tw/faq/php-tutorial" title="PHP教程" class="phpgenera_Details_mainR4_bottom_title">PHP教程</a> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms_info"> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms_infos"> <img src="/static/imghw/eyess.png" alt="" /> <span>1488</span> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms_infos"> <img src="/static/imghw/tiezi.png" alt="" /> <span>72</span> </div> </div> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR3_more"> <a href="http://ipnx.cn/zh-tw/faq/zt">顯示更多</a> </div> </div> </div> </div> </div> <div id="wjcelcm34c" class="Article_Details_main2"> <div id="wjcelcm34c" class="phpgenera_Details_mainL4"> <div id="wjcelcm34c" class="phpmain1_2_top"> <a href="javascript:void(0);" class="phpmain1_2_top_title">Related knowledge<img src="/static/imghw/index2_title2.png" alt="" /></a> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainL4_info"> <div id="wjcelcm34c" class="phphistorical_Version2_mids"> <a href="http://ipnx.cn/zh-tw/faq/1796839536.html" title="PHP變量範(fàn)圍解釋了" class="phphistorical_Version2_mids_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/default1.png" class="lazy" data-src="https://img.php.cn/upload/article/001/253/068/175269699023092.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="PHP變量範(fàn)圍解釋了" /> </a> <a href="http://ipnx.cn/zh-tw/faq/1796839536.html" title="PHP變量範(fàn)圍解釋了" class="phphistorical_Version2_mids_title">PHP變量範(fàn)圍解釋了</a> <span id="wjcelcm34c" class="Articlelist_txts_time">Jul 17, 2025 am 04:16 AM</span> <p class="Articlelist_txts_p">PHP變量作用域常見問題及解決方法包括:1.函數(shù)內(nèi)部無法訪問全局變量,需使用global關(guān)鍵字或參數(shù)傳入;2.靜態(tài)變量用static聲明,只初始化一次並在多次調(diào)用間保持值;3.超全局變量如$_GET、$_POST可在任何作用域直接使用,但需注意安全過濾;4.匿名函數(shù)需通過use關(guān)鍵字引入父作用域變量,修改外部變量則需傳遞引用。掌握這些規(guī)則有助於避免錯誤並提升代碼穩(wěn)定性。</p> </div> <div id="wjcelcm34c" class="phphistorical_Version2_mids"> <a href="http://ipnx.cn/zh-tw/faq/1796832599.html" title="如何在PHP中牢固地處理文件上傳?" class="phphistorical_Version2_mids_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/default1.png" class="lazy" data-src="https://img.php.cn/upload/article/001/253/068/175191342169363.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="如何在PHP中牢固地處理文件上傳?" /> </a> <a href="http://ipnx.cn/zh-tw/faq/1796832599.html" title="如何在PHP中牢固地處理文件上傳?" class="phphistorical_Version2_mids_title">如何在PHP中牢固地處理文件上傳?</a> <span id="wjcelcm34c" class="Articlelist_txts_time">Jul 08, 2025 am 02:37 AM</span> <p class="Articlelist_txts_p">要安全處理PHP文件上傳需驗證來源與類型、控製文件名與路徑、設(shè)置服務(wù)器限制並二次處理媒體文件。 1.驗證上傳來源通過token防止CSRF並通過finfo_file檢測真實MIME類型使用白名單控制;2.重命名文件為隨機字符串並根據(jù)檢測類型決定擴展名存儲至非Web目錄;3.PHP配置限制上傳大小及臨時目錄Nginx/Apache禁止訪問上傳目錄;4.GD庫重新保存圖片清除潛在惡意數(shù)據(jù)。</p> </div> <div id="wjcelcm34c" class="phphistorical_Version2_mids"> <a href="http://ipnx.cn/zh-tw/faq/1796840634.html" title="在PHP中評論代碼" class="phphistorical_Version2_mids_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/default1.png" class="lazy" data-src="https://img.php.cn/upload/article/001/253/068/175278584067051.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="在PHP中評論代碼" /> </a> <a href="http://ipnx.cn/zh-tw/faq/1796840634.html" title="在PHP中評論代碼" class="phphistorical_Version2_mids_title">在PHP中評論代碼</a> <span id="wjcelcm34c" class="Articlelist_txts_time">Jul 18, 2025 am 04:57 AM</span> <p class="Articlelist_txts_p">PHP註釋代碼常用方法有三種:1.單行註釋用//或#屏蔽一行代碼,推薦使用//;2.多行註釋用/.../包裹代碼塊,不可嵌套但可跨行;3.組合技巧註釋如用/if(){}/控制邏輯塊,或配合編輯器快捷鍵提升效率,使用時需注意閉合符號和避免嵌套。</p> </div> <div id="wjcelcm34c" class="phphistorical_Version2_mids"> <a href="http://ipnx.cn/zh-tw/faq/1796834881.html" title="發(fā)電機如何在PHP中工作?" class="phphistorical_Version2_mids_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/default1.png" class="lazy" data-src="https://img.php.cn/upload/article/001/253/068/175217473076928.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="發(fā)電機如何在PHP中工作?" /> </a> <a href="http://ipnx.cn/zh-tw/faq/1796834881.html" title="發(fā)電機如何在PHP中工作?" class="phphistorical_Version2_mids_title">發(fā)電機如何在PHP中工作?</a> <span id="wjcelcm34c" class="Articlelist_txts_time">Jul 11, 2025 am 03:12 AM</span> <p class="Articlelist_txts_p">AgeneratorinPHPisamemory-efficientwaytoiterateoverlargedatasetsbyyieldingvaluesoneatatimeinsteadofreturningthemallatonce.1.Generatorsusetheyieldkeywordtoproducevaluesondemand,reducingmemoryusage.2.Theyareusefulforhandlingbigloops,readinglargefiles,or</p> </div> <div id="wjcelcm34c" class="phphistorical_Version2_mids"> <a href="http://ipnx.cn/zh-tw/faq/1796840616.html" title="撰寫PHP評論的提示" class="phphistorical_Version2_mids_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/default1.png" class="lazy" data-src="https://img.php.cn/upload/article/001/253/068/175278548014857.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="撰寫PHP評論的提示" /> </a> <a href="http://ipnx.cn/zh-tw/faq/1796840616.html" title="撰寫PHP評論的提示" class="phphistorical_Version2_mids_title">撰寫PHP評論的提示</a> <span id="wjcelcm34c" class="Articlelist_txts_time">Jul 18, 2025 am 04:51 AM</span> <p class="Articlelist_txts_p">寫好PHP註釋的關(guān)鍵在於明確目的與規(guī)範(fàn),註釋應(yīng)解釋“為什麼”而非“做了什麼”,避免冗餘或過於簡單。 1.使用統(tǒng)一格式,如docblock(/*/)用於類、方法說明,提升可讀性與工具兼容性;2.強調(diào)邏輯背後的原因,如說明為何需手動輸出JS跳轉(zhuǎn);3.在復(fù)雜代碼前添加總覽性說明,分步驟描述流程,幫助理解整體思路;4.合理使用TODO和FIXME標(biāo)記待辦事項與問題,便於後續(xù)追蹤與協(xié)作。好的註釋能降低溝通成本,提升代碼維護效率。</p> </div> <div id="wjcelcm34c" class="phphistorical_Version2_mids"> <a href="http://ipnx.cn/zh-tw/faq/1796840620.html" title="快速PHP安裝教程" class="phphistorical_Version2_mids_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/default1.png" class="lazy" data-src="https://img.php.cn/upload/article/001/253/068/175278556155781.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="快速PHP安裝教程" /> </a> <a href="http://ipnx.cn/zh-tw/faq/1796840620.html" title="快速PHP安裝教程" class="phphistorical_Version2_mids_title">快速PHP安裝教程</a> <span id="wjcelcm34c" class="Articlelist_txts_time">Jul 18, 2025 am 04:52 AM</span> <p class="Articlelist_txts_p">ToinstallPHPquickly,useXAMPPonWindowsorHomebrewonmacOS.1.OnWindows,downloadandinstallXAMPP,selectcomponents,startApache,andplacefilesinhtdocs.2.Alternatively,manuallyinstallPHPfromphp.netandsetupaserverlikeApache.3.OnmacOS,installHomebrew,thenrun'bre</p> </div> <div id="wjcelcm34c" class="phphistorical_Version2_mids"> <a href="http://ipnx.cn/zh-tw/faq/1796835692.html" title="如何通過php中的索引訪問字符串中的字符" class="phphistorical_Version2_mids_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/default1.png" class="lazy" data-src="https://img.php.cn/upload/article/001/431/639/175226134074442.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="如何通過php中的索引訪問字符串中的字符" /> </a> <a href="http://ipnx.cn/zh-tw/faq/1796835692.html" title="如何通過php中的索引訪問字符串中的字符" class="phphistorical_Version2_mids_title">如何通過php中的索引訪問字符串中的字符</a> <span id="wjcelcm34c" class="Articlelist_txts_time">Jul 12, 2025 am 03:15 AM</span> <p class="Articlelist_txts_p">在PHP中獲取字符串特定索引字符可用方括號或花括號,但推薦方括號;索引從0開始,超出範(fàn)圍訪問返回空值,不可賦值;處理多字節(jié)字符需用mb_substr。例如:$str="hello";echo$str[0];輸出h;而中文等字符需用mb_substr($str,1,1)獲取正確結(jié)果;實際應(yīng)用中循環(huán)訪問前應(yīng)檢查字符串長度,動態(tài)字符串需驗證有效性,多語言項目建議統(tǒng)一使用多字節(jié)安全函數(shù)。</p> </div> <div id="wjcelcm34c" class="phphistorical_Version2_mids"> <a href="http://ipnx.cn/zh-tw/faq/1796840626.html" title="學(xué)習(xí)PHP:初學(xué)者指南" class="phphistorical_Version2_mids_img"> <img onerror="this.onerror=''; this.src='/static/imghw/default1.png'" src="/static/imghw/default1.png" class="lazy" data-src="https://img.php.cn/upload/article/001/253/068/175278568042274.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="學(xué)習(xí)PHP:初學(xué)者指南" /> </a> <a href="http://ipnx.cn/zh-tw/faq/1796840626.html" title="學(xué)習(xí)PHP:初學(xué)者指南" class="phphistorical_Version2_mids_title">學(xué)習(xí)PHP:初學(xué)者指南</a> <span id="wjcelcm34c" class="Articlelist_txts_time">Jul 18, 2025 am 04:54 AM</span> <p class="Articlelist_txts_p">易於效率,啟動啟動tingupalocalserverenverenvirestoolslikexamppandacodeeditorlikevscode.1)installxamppforapache,mysql,andphp.2)uscodeeditorforsyntaxssupport.3)</p> </div> </div> <a href="http://ipnx.cn/zh-tw/be/" class="phpgenera_Details_mainL4_botton"> <span>See all articles</span> <img src="/static/imghw/down_right.png" alt="" /> </a> </div> </div> </div> </main> <footer> <div id="wjcelcm34c" class="footer"> <div id="wjcelcm34c" class="footertop"> <img src="/static/imghw/logo.png" alt=""> <p>公益線上PHP培訓(xùn),幫助PHP學(xué)習(xí)者快速成長!</p> </div> <div id="wjcelcm34c" class="footermid"> <a href="http://ipnx.cn/zh-tw/about/us.html">關(guān)於我們</a> <a href="http://ipnx.cn/zh-tw/about/disclaimer.html">免責(zé)聲明</a> <a href="http://ipnx.cn/zh-tw/update/article_0_1.html">Sitemap</a> </div> <div id="wjcelcm34c" class="footerbottom"> <p> ? php.cn All rights reserved </p> </div> </div> </footer> <input type="hidden" id="verifycode" value="/captcha.html"> <link rel='stylesheet' id='_main-css' href='/static/css/viewer.min.css?2' type='text/css' media='all' /> <footer> <div class="friendship-link"> <p>感谢您访问我们的网站,您可能还对以下资源感兴趣:</p> <a href="http://ipnx.cn/" title="亚洲国产日韩欧美一区二区三区">亚洲国产日韩欧美一区二区三区</a> <div class="friend-links"> </div> </div> </footer> <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body><div id="4anuu" class="pl_css_ganrao" style="display: none;"><span id="4anuu"><pre id="4anuu"><pre id="4anuu"><sub id="4anuu"></sub></pre></pre></span><form id="4anuu"><label id="4anuu"></label></form><em id="4anuu"><li id="4anuu"><style id="4anuu"></style></li></em><del id="4anuu"></del><big id="4anuu"></big><form id="4anuu"><tbody id="4anuu"></tbody></form><dl id="4anuu"><xmp id="4anuu"></xmp></dl><tr id="4anuu"></tr><sub id="4anuu"><tr id="4anuu"><label id="4anuu"><div id="4anuu"></div></label></tr></sub><samp id="4anuu"></samp><strike id="4anuu"></strike><b id="4anuu"></b><span id="4anuu"></span><i id="4anuu"></i><ins id="4anuu"><abbr id="4anuu"></abbr></ins><th id="4anuu"></th><span id="4anuu"></span><nav id="4anuu"><b id="4anuu"><mark id="4anuu"><legend id="4anuu"></legend></mark></b></nav><div id="4anuu"></div><span id="4anuu"><tbody id="4anuu"></tbody></span><b id="4anuu"><kbd id="4anuu"><output id="4anuu"><tr id="4anuu"></tr></output></kbd></b><nobr id="4anuu"><listing id="4anuu"></listing></nobr><video id="4anuu"><em id="4anuu"></em></video><center id="4anuu"></center><b id="4anuu"></b><small id="4anuu"></small><div id="4anuu"><tfoot id="4anuu"><legend id="4anuu"><cite id="4anuu"></cite></legend></tfoot></div><u id="4anuu"></u><p id="4anuu"></p><center id="4anuu"><font id="4anuu"><ins id="4anuu"></ins></font></center><strike id="4anuu"></strike><video id="4anuu"><meter id="4anuu"></meter></video><dfn id="4anuu"></dfn><th id="4anuu"></th><p id="4anuu"></p><tr id="4anuu"><em id="4anuu"><menuitem id="4anuu"></menuitem></em></tr><dd id="4anuu"><s id="4anuu"><var id="4anuu"><li id="4anuu"></li></var></s></dd><strong id="4anuu"></strong><nav id="4anuu"></nav><em id="4anuu"></em><ol id="4anuu"><table id="4anuu"><output id="4anuu"><tt id="4anuu"></tt></output></table></ol><ul id="4anuu"></ul><sup id="4anuu"></sup><u id="4anuu"></u><input id="4anuu"><th id="4anuu"><tr id="4anuu"><dfn id="4anuu"></dfn></tr></th></input><th id="4anuu"><tr id="4anuu"></tr></th><button id="4anuu"><u id="4anuu"><form id="4anuu"><abbr id="4anuu"></abbr></form></u></button><input id="4anuu"></input><label id="4anuu"></label><sub id="4anuu"><tfoot id="4anuu"></tfoot></sub><source id="4anuu"><wbr id="4anuu"><sup id="4anuu"></sup></wbr></source><thead id="4anuu"><label id="4anuu"><small id="4anuu"><kbd id="4anuu"></kbd></small></label></thead><listing id="4anuu"></listing><label id="4anuu"></label><table id="4anuu"></table><pre id="4anuu"><td id="4anuu"><dd id="4anuu"><tbody id="4anuu"></tbody></dd></td></pre><thead id="4anuu"><acronym id="4anuu"><rt id="4anuu"></rt></acronym></thead><dd id="4anuu"></dd><nobr id="4anuu"></nobr><button id="4anuu"><style id="4anuu"></style></button><pre id="4anuu"></pre><p id="4anuu"></p><form id="4anuu"></form><abbr id="4anuu"></abbr><strong id="4anuu"><b id="4anuu"></b></strong><ruby id="4anuu"><option id="4anuu"><small id="4anuu"><output id="4anuu"></output></small></option></ruby><tr id="4anuu"><ruby id="4anuu"><big id="4anuu"><span id="4anuu"></span></big></ruby></tr><listing id="4anuu"><video id="4anuu"><small id="4anuu"></small></video></listing><menuitem id="4anuu"><thead id="4anuu"><input id="4anuu"></input></thead></menuitem><pre id="4anuu"><tt id="4anuu"><ul id="4anuu"></ul></tt></pre><div id="4anuu"><rt id="4anuu"></rt></div><input id="4anuu"></input><center id="4anuu"><xmp id="4anuu"><blockquote id="4anuu"><span id="4anuu"></span></blockquote></xmp></center><code id="4anuu"><strong id="4anuu"><p id="4anuu"><center id="4anuu"></center></p></strong></code><pre id="4anuu"><bdo id="4anuu"></bdo></pre><dfn id="4anuu"></dfn><td id="4anuu"><strike id="4anuu"></strike></td><bdo id="4anuu"><li id="4anuu"></li></bdo><tbody id="4anuu"><tt id="4anuu"><center id="4anuu"><dl id="4anuu"></dl></center></tt></tbody><small id="4anuu"><abbr id="4anuu"><rp id="4anuu"><delect id="4anuu"></delect></rp></abbr></small><legend id="4anuu"><abbr id="4anuu"></abbr></legend><pre id="4anuu"></pre><nobr id="4anuu"><progress id="4anuu"></progress></nobr><ol id="4anuu"><strike id="4anuu"><dl id="4anuu"></dl></strike></ol><abbr id="4anuu"></abbr><sup id="4anuu"><big id="4anuu"><samp id="4anuu"><em id="4anuu"></em></samp></big></sup><dd id="4anuu"></dd><small id="4anuu"><small id="4anuu"><p id="4anuu"><span id="4anuu"></span></p></small></small><big id="4anuu"></big><track id="4anuu"><output id="4anuu"><blockquote id="4anuu"></blockquote></output></track><legend id="4anuu"><pre id="4anuu"></pre></legend><dfn id="4anuu"></dfn><code id="4anuu"></code><source id="4anuu"></source><dl id="4anuu"><xmp id="4anuu"></xmp></dl><pre id="4anuu"></pre><thead id="4anuu"></thead><dl id="4anuu"></dl></div> </html>