<sup id="ndhoc"></sup>

  • <strike id="ndhoc"></strike>
  • \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 \/\/添加水印選項(xiàng)\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>這里面主要是添加水印選項(xiàng),如果選中添加水印則將logo.png作為水印圖片和原來的圖片合并在一起。<\/p>\n<p>在預(yù)覽文件中添加了對(duì)應(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>方法把兩個(gè)圖片合并在一起造成水印效果。來看看這個(gè)方法的方法原型和參數(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 時(shí),實(shí)際上什么也沒做,當(dāng)為 100 時(shí)對(duì)于調(diào)色板圖像本函數(shù)和 imagecopy() 完全一樣,它對(duì)真彩色圖像實(shí)現(xiàn)了 alpha 透明。<br>\n<\/p>\n<p>以上內(nèi)容是本文介紹PHP給圖片添加水印 壓縮 剪切的封裝類的全部內(nèi)容,希望大家對(duì)本文介紹感興趣。<\/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/" 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="Community" class="head_nava head_nava-template1">Community</a> <div class="wjcelcm34c" id="dropdown-template1" style="display: none;"> <div id="wjcelcm34c" class="languagechoose"> <a href="http://ipnx.cn/article.html" title="Articles" class="languagechoosea on">Articles</a> <a href="http://ipnx.cn/faq/zt" title="Topics" class="languagechoosea">Topics</a> <a href="http://ipnx.cn/wenda.html" title="Q&A" class="languagechoosea">Q&A</a> </div> </div> </div> <div id="wjcelcm34c" class="head_navs"> <a href="javascript:;" title="Learn" class="head_nava head_nava-template1_1">Learn</a> <div class="wjcelcm34c" id="dropdown-template1_1" style="display: none;"> <div id="wjcelcm34c" class="languagechoose"> <a href="http://ipnx.cn/course.html" title="Course" class="languagechoosea on">Course</a> <a href="http://ipnx.cn/dic/" title="Programming Dictionary" class="languagechoosea">Programming Dictionary</a> </div> </div> </div> <div id="wjcelcm34c" class="head_navs"> <a href="javascript:;" title="Tools Library" class="head_nava head_nava-template1_2">Tools Library</a> <div class="wjcelcm34c" id="dropdown-template1_2" style="display: none;"> <div id="wjcelcm34c" class="languagechoose"> <a href="http://ipnx.cn/toolset/development-tools" title="Development tools" class="languagechoosea on">Development tools</a> <a href="http://ipnx.cn/toolset/website-source-code" title="Website Source Code" class="languagechoosea">Website Source Code</a> <a href="http://ipnx.cn/toolset/php-libraries" title="PHP Libraries" class="languagechoosea">PHP Libraries</a> <a href="http://ipnx.cn/toolset/js-special-effects" title="JS special effects" class="languagechoosea on">JS special effects</a> <a href="http://ipnx.cn/toolset/website-materials" title="Website Materials" class="languagechoosea on">Website Materials</a> <a href="http://ipnx.cn/toolset/extension-plug-ins" title="Extension plug-ins" class="languagechoosea on">Extension plug-ins</a> </div> </div> </div> <div id="wjcelcm34c" class="head_navs"> <a href="http://ipnx.cn/ai" title="AI Tools" class="head_nava head_nava-template1_3">AI Tools</a> </div> <div id="wjcelcm34c" class="head_navs"> <a href="javascript:;" title="Leisure" class="head_nava head_nava-template1_3">Leisure</a> <div class="wjcelcm34c" id="dropdown-template1_3" style="display: none;"> <div id="wjcelcm34c" class="languagechoose"> <a href="http://ipnx.cn/game" title="Game Download" class="languagechoosea on">Game Download</a> <a href="http://ipnx.cn/mobile-game-tutorial/" title="Game Tutorials" class="languagechoosea">Game Tutorials</a> </div> </div> </div> </div> </div> <div id="wjcelcm34c" class="head_search"> <input id="key_words" onkeydown="if (event.keyCode == 13) searchs('en')" class="search-input" type="text" autocomplete="off" name="keywords" required="required" placeholder="Block,address,transaction,news" value=""> <a href="javascript:;" title="search" onclick="searchs('en')"><img src="/static/imghw/find.png" alt="search"></a> </div> <div id="wjcelcm34c" class="head_right"> <div id="wjcelcm34c" class="haed_language"> <a href="javascript:;" class="layui-btn haed_language_btn">English<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:;" title="English" class="languagechoosea">English</a> <a href="javascript:setlang('zh-tw');" 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/" title="Home" class="phpgenera_Details_mainL1a">Home</a> <img src="/static/imghw/top_right.png" alt="" /> <a href="http://ipnx.cn/be/" class="phpgenera_Details_mainL1a">Backend Development</a> <img src="/static/imghw/top_right.png" alt="" /> <a href="http://ipnx.cn/php-weizijiaocheng.html" class="phpgenera_Details_mainL1a">PHP Tutorial</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/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/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">add watermark</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>給圖片添加水印,其實(shí)就是把原來的圖片和水印添加在一起,下面小編把最近整理的資料分享給大家。</p> <p>php對(duì)圖片文件的操作主要是利用GD庫擴(kuò)展。當(dāng)我們頻繁利用php對(duì)圖片進(jìn)行操作時(shí),會(huì)自然封裝很多函數(shù),否則會(huì)寫太多重復(fù)的代碼。當(dāng)有很多對(duì)圖片的相關(guān)函數(shù)的時(shí)候,我們可以考慮將這些函數(shù)也整理一下,因而就有了封裝成類的想法。</p> <p> <strong> 操作圖片主要?dú)v經(jīng)四個(gè)步驟:</strong></p> <p>??????? 第一步:打開圖片</p> <p>??????? 第二步:操作圖片<br> </p> <p>??????? 第三步:輸出圖片<br> </p> <p>??????? 第四步:銷毀圖片<br> </p> <p>  1,3,4三個(gè)步驟每次都要寫,每次又都差不多。真正需要變通的只有操作圖片的這一步驟了。操作圖片又往往通過1或多個(gè)主要的GD函數(shù)來完成。</p> <p>  <strong>本文封裝類里面的四種方法,文字水?。╥magettftext()),圖片水?。╥magecopymerge()),圖片壓縮,圖片剪切(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>如果還需要其他操作,只需要再往這個(gè)類里面添加就好啦~~</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 />'; //添加水印選項(xiàng) 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>這里面主要是添加水印選項(xiàng),如果選中添加水印則將logo.png作為水印圖片和原來的圖片合并在一起。</p> <p>在預(yù)覽文件中添加了對(duì)應(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>方法把兩個(gè)圖片合并在一起造成水印效果。來看看這個(gè)方法的方法原型和參數(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 時(shí),實(shí)際上什么也沒做,當(dāng)為 100 時(shí)對(duì)于調(diào)色板圖像本函數(shù)和 imagecopy() 完全一樣,它對(duì)真彩色圖像實(shí)現(xiàn)了 alpha 透明。<br> </p> <p>以上內(nèi)容是本文介紹PHP給圖片添加水印 壓縮 剪切的封裝類的全部內(nèi)容,希望大家對(duì)本文介紹感興趣。</p> </div> </div> <div id="wjcelcm34c" class="wzconShengming_sp"> <div id="wjcelcm34c" class="bzsmdiv_sp">Statement of this Website</div> <div>The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact 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>Hot Article</h2> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottom"> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms"> <a href="http://ipnx.cn/faq/1796832397.html" title="Grass Wonder Build Guide | Uma Musume Pretty Derby" class="phpgenera_Details_mainR4_bottom_title">Grass Wonder Build Guide | Uma Musume Pretty Derby</a> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms_info"> <span>3 weeks ago</span> <span>By Jack chen</span> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms"> <a href="http://ipnx.cn/faq/1796833110.html" title="Roblox: 99 Nights In The Forest - All Badges And How To Unlock Them" class="phpgenera_Details_mainR4_bottom_title">Roblox: 99 Nights In The Forest - All Badges And How To Unlock Them</a> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms_info"> <span>3 weeks ago</span> <span>By DDD</span> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms"> <a href="http://ipnx.cn/faq/1796831605.html" title="Uma Musume Pretty Derby Banner Schedule (July 2025)" class="phpgenera_Details_mainR4_bottom_title">Uma Musume Pretty Derby Banner Schedule (July 2025)</a> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms_info"> <span>4 weeks ago</span> <span>By Jack chen</span> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms"> <a href="http://ipnx.cn/faq/1796829586.html" title="Today's Connections hint and answer 3rd July for 753" class="phpgenera_Details_mainR4_bottom_title">Today's Connections hint and answer 3rd July for 753</a> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms_info"> <span>1 months ago</span> <span>By Jack chen</span> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms"> <a href="http://ipnx.cn/faq/1796831905.html" title="Windows Security is blank or not showing options" class="phpgenera_Details_mainR4_bottom_title">Windows Security is blank or not showing options</a> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms_info"> <span>4 weeks ago</span> <span>By 下次還敢</span> </div> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR3_more"> <a href="http://ipnx.cn/article.html">Show More</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>Hot AI Tools</h2> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR3_bottom"> <div id="wjcelcm34c" class="phpmain_tab2_mids_top"> <a href="http://ipnx.cn/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/ai/undress-ai-tool" title="Undress AI Tool" class="phpmain_tab2_mids_title"> <h3>Undress AI Tool</h3> </a> <p>Undress images for free</p> </div> </div> <div id="wjcelcm34c" class="phpmain_tab2_mids_top"> <a href="http://ipnx.cn/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/ai/undresserai-undress" title="Undresser.AI Undress" class="phpmain_tab2_mids_title"> <h3>Undresser.AI Undress</h3> </a> <p>AI-powered app for creating realistic nude photos</p> </div> </div> <div id="wjcelcm34c" class="phpmain_tab2_mids_top"> <a href="http://ipnx.cn/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/ai/ai-clothes-remover" title="AI Clothes Remover" class="phpmain_tab2_mids_title"> <h3>AI Clothes Remover</h3> </a> <p>Online AI tool for removing clothes from photos.</p> </div> </div> <div id="wjcelcm34c" class="phpmain_tab2_mids_top"> <a href="http://ipnx.cn/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/ai/clothoffio" title="Clothoff.io" class="phpmain_tab2_mids_title"> <h3>Clothoff.io</h3> </a> <p>AI clothes remover</p> </div> </div> <div id="wjcelcm34c" class="phpmain_tab2_mids_top"> <a href="http://ipnx.cn/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/ai/video-swap" title="Video Face Swap" class="phpmain_tab2_mids_title"> <h3>Video Face Swap</h3> </a> <p>Swap faces in any video effortlessly with our completely free AI face swap tool!</p> </div> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR3_more"> <a href="http://ipnx.cn/ai">Show More</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>Hot Article</h2> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottom"> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms"> <a href="http://ipnx.cn/faq/1796832397.html" title="Grass Wonder Build Guide | Uma Musume Pretty Derby" class="phpgenera_Details_mainR4_bottom_title">Grass Wonder Build Guide | Uma Musume Pretty Derby</a> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms_info"> <span>3 weeks ago</span> <span>By Jack chen</span> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms"> <a href="http://ipnx.cn/faq/1796833110.html" title="Roblox: 99 Nights In The Forest - All Badges And How To Unlock Them" class="phpgenera_Details_mainR4_bottom_title">Roblox: 99 Nights In The Forest - All Badges And How To Unlock Them</a> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms_info"> <span>3 weeks ago</span> <span>By DDD</span> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms"> <a href="http://ipnx.cn/faq/1796831605.html" title="Uma Musume Pretty Derby Banner Schedule (July 2025)" class="phpgenera_Details_mainR4_bottom_title">Uma Musume Pretty Derby Banner Schedule (July 2025)</a> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms_info"> <span>4 weeks ago</span> <span>By Jack chen</span> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms"> <a href="http://ipnx.cn/faq/1796829586.html" title="Today's Connections hint and answer 3rd July for 753" class="phpgenera_Details_mainR4_bottom_title">Today's Connections hint and answer 3rd July for 753</a> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms_info"> <span>1 months ago</span> <span>By Jack chen</span> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms"> <a href="http://ipnx.cn/faq/1796831905.html" title="Windows Security is blank or not showing options" class="phpgenera_Details_mainR4_bottom_title">Windows Security is blank or not showing options</a> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms_info"> <span>4 weeks ago</span> <span>By 下次還敢</span> </div> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR3_more"> <a href="http://ipnx.cn/article.html">Show More</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>Hot Tools</h2> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR3_bottom"> <div id="wjcelcm34c" class="phpmain_tab2_mids_top"> <a href="http://ipnx.cn/toolset/development-tools/92" title="Notepad++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="Notepad++7.3.1" /> </a> <div id="wjcelcm34c" class="phpmain_tab2_mids_info"> <a href="http://ipnx.cn/toolset/development-tools/92" title="Notepad++7.3.1" class="phpmain_tab2_mids_title"> <h3>Notepad++7.3.1</h3> </a> <p>Easy-to-use and free code editor</p> </div> </div> <div id="wjcelcm34c" class="phpmain_tab2_mids_top"> <a href="http://ipnx.cn/toolset/development-tools/93" title="SublimeText3 Chinese version" 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 Chinese version" /> </a> <div id="wjcelcm34c" class="phpmain_tab2_mids_info"> <a href="http://ipnx.cn/toolset/development-tools/93" title="SublimeText3 Chinese version" class="phpmain_tab2_mids_title"> <h3>SublimeText3 Chinese version</h3> </a> <p>Chinese version, very easy to use</p> </div> </div> <div id="wjcelcm34c" class="phpmain_tab2_mids_top"> <a href="http://ipnx.cn/toolset/development-tools/121" title="Zend Studio 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="Zend Studio 13.0.1" /> </a> <div id="wjcelcm34c" class="phpmain_tab2_mids_info"> <a href="http://ipnx.cn/toolset/development-tools/121" title="Zend Studio 13.0.1" class="phpmain_tab2_mids_title"> <h3>Zend Studio 13.0.1</h3> </a> <p>Powerful PHP integrated development environment</p> </div> </div> <div id="wjcelcm34c" class="phpmain_tab2_mids_top"> <a href="http://ipnx.cn/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/toolset/development-tools/469" title="Dreamweaver CS6" class="phpmain_tab2_mids_title"> <h3>Dreamweaver CS6</h3> </a> <p>Visual web development tools</p> </div> </div> <div id="wjcelcm34c" class="phpmain_tab2_mids_top"> <a href="http://ipnx.cn/toolset/development-tools/500" title="SublimeText3 Mac version" 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 version" /> </a> <div id="wjcelcm34c" class="phpmain_tab2_mids_info"> <a href="http://ipnx.cn/toolset/development-tools/500" title="SublimeText3 Mac version" class="phpmain_tab2_mids_title"> <h3>SublimeText3 Mac version</h3> </a> <p>God-level code editing software (SublimeText3)</p> </div> </div> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR3_more"> <a href="http://ipnx.cn/ai">Show More</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>Hot Topics</h2> </div> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottom"> <div id="wjcelcm34c" class="phpgenera_Details_mainR4_bottoms"> <a href="http://ipnx.cn/faq/laravel-tutori" title="Laravel Tutorial" class="phpgenera_Details_mainR4_bottom_title">Laravel Tutorial</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/faq/php-tutorial" title="PHP Tutorial" class="phpgenera_Details_mainR4_bottom_title">PHP Tutorial</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/faq/zt">Show More</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/faq/1796839536.html" title="PHP Variable Scope Explained" 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 Variable Scope Explained" /> </a> <a href="http://ipnx.cn/faq/1796839536.html" title="PHP Variable Scope Explained" class="phphistorical_Version2_mids_title">PHP Variable Scope Explained</a> <span id="wjcelcm34c" class="Articlelist_txts_time">Jul 17, 2025 am 04:16 AM</span> <p class="Articlelist_txts_p">Common problems and solutions for PHP variable scope include: 1. The global variable cannot be accessed within the function, and it needs to be passed in using the global keyword or parameter; 2. The static variable is declared with static, and it is only initialized once and the value is maintained between multiple calls; 3. Hyperglobal variables such as $_GET and $_POST can be used directly in any scope, but you need to pay attention to safe filtering; 4. Anonymous functions need to introduce parent scope variables through the use keyword, and when modifying external variables, you need to pass a reference. Mastering these rules can help avoid errors and improve code stability.</p> </div> <div id="wjcelcm34c" class="phphistorical_Version2_mids"> <a href="http://ipnx.cn/faq/1796832599.html" title="How to handle File Uploads securely in 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="How to handle File Uploads securely in PHP?" /> </a> <a href="http://ipnx.cn/faq/1796832599.html" title="How to handle File Uploads securely in PHP?" class="phphistorical_Version2_mids_title">How to handle File Uploads securely in PHP?</a> <span id="wjcelcm34c" class="Articlelist_txts_time">Jul 08, 2025 am 02:37 AM</span> <p class="Articlelist_txts_p">To safely handle PHP file uploads, you need to verify the source and type, control the file name and path, set server restrictions, and process media files twice. 1. Verify the upload source to prevent CSRF through token and detect the real MIME type through finfo_file using whitelist control; 2. Rename the file to a random string and determine the extension to store it in a non-Web directory according to the detection type; 3. PHP configuration limits the upload size and temporary directory Nginx/Apache prohibits access to the upload directory; 4. The GD library resaves the pictures to clear potential malicious data.</p> </div> <div id="wjcelcm34c" class="phphistorical_Version2_mids"> <a href="http://ipnx.cn/faq/1796840634.html" title="Commenting Out Code in 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="Commenting Out Code in PHP" /> </a> <a href="http://ipnx.cn/faq/1796840634.html" title="Commenting Out Code in PHP" class="phphistorical_Version2_mids_title">Commenting Out Code in PHP</a> <span id="wjcelcm34c" class="Articlelist_txts_time">Jul 18, 2025 am 04:57 AM</span> <p class="Articlelist_txts_p">There are three common methods for PHP comment code: 1. Use // or # to block one line of code, and it is recommended to use //; 2. Use /.../ to wrap code blocks with multiple lines, which cannot be nested but can be crossed; 3. Combination skills comments such as using /if(){}/ to control logic blocks, or to improve efficiency with editor shortcut keys, you should pay attention to closing symbols and avoid nesting when using them.</p> </div> <div id="wjcelcm34c" class="phphistorical_Version2_mids"> <a href="http://ipnx.cn/faq/1796834881.html" title="How Do Generators Work in 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="How Do Generators Work in PHP?" /> </a> <a href="http://ipnx.cn/faq/1796834881.html" title="How Do Generators Work in PHP?" class="phphistorical_Version2_mids_title">How Do Generators Work in 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/faq/1796840616.html" title="Tips for Writing PHP Comments" 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="Tips for Writing PHP Comments" /> </a> <a href="http://ipnx.cn/faq/1796840616.html" title="Tips for Writing PHP Comments" class="phphistorical_Version2_mids_title">Tips for Writing PHP Comments</a> <span id="wjcelcm34c" class="Articlelist_txts_time">Jul 18, 2025 am 04:51 AM</span> <p class="Articlelist_txts_p">The key to writing PHP comments is to clarify the purpose and specifications. Comments should explain "why" rather than "what was done", avoiding redundancy or too simplicity. 1. Use a unified format, such as docblock (/*/) for class and method descriptions to improve readability and tool compatibility; 2. Emphasize the reasons behind the logic, such as why JS jumps need to be output manually; 3. Add an overview description before complex code, describe the process in steps, and help understand the overall idea; 4. Use TODO and FIXME rationally to mark to-do items and problems to facilitate subsequent tracking and collaboration. Good annotations can reduce communication costs and improve code maintenance efficiency.</p> </div> <div id="wjcelcm34c" class="phphistorical_Version2_mids"> <a href="http://ipnx.cn/faq/1796840620.html" title="Quick PHP Installation Tutorial" 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="Quick PHP Installation Tutorial" /> </a> <a href="http://ipnx.cn/faq/1796840620.html" title="Quick PHP Installation Tutorial" class="phphistorical_Version2_mids_title">Quick PHP Installation Tutorial</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/faq/1796835692.html" title="How to access a character in a string by index in 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="How to access a character in a string by index in PHP" /> </a> <a href="http://ipnx.cn/faq/1796835692.html" title="How to access a character in a string by index in PHP" class="phphistorical_Version2_mids_title">How to access a character in a string by index in PHP</a> <span id="wjcelcm34c" class="Articlelist_txts_time">Jul 12, 2025 am 03:15 AM</span> <p class="Articlelist_txts_p">In PHP, you can use square brackets or curly braces to obtain string specific index characters, but square brackets are recommended; the index starts from 0, and the access outside the range returns a null value and cannot be assigned a value; mb_substr is required to handle multi-byte characters. For example: $str="hello";echo$str[0]; output h; and Chinese characters such as mb_substr($str,1,1) need to obtain the correct result; in actual applications, the length of the string should be checked before looping, dynamic strings need to be verified for validity, and multilingual projects recommend using multi-byte security functions uniformly.</p> </div> <div id="wjcelcm34c" class="phphistorical_Version2_mids"> <a href="http://ipnx.cn/faq/1796840626.html" title="Learning PHP: A Beginner's Guide" 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="Learning PHP: A Beginner's Guide" /> </a> <a href="http://ipnx.cn/faq/1796840626.html" title="Learning PHP: A Beginner's Guide" class="phphistorical_Version2_mids_title">Learning PHP: A Beginner's Guide</a> <span id="wjcelcm34c" class="Articlelist_txts_time">Jul 18, 2025 am 04:54 AM</span> <p class="Articlelist_txts_p">TolearnPHPeffectively,startbysettingupalocalserverenvironmentusingtoolslikeXAMPPandacodeeditorlikeVSCode.1)InstallXAMPPforApache,MySQL,andPHP.2)Useacodeeditorforsyntaxsupport.3)TestyoursetupwithasimplePHPfile.Next,learnPHPbasicsincludingvariables,ech</p> </div> </div> <a href="http://ipnx.cn/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>Public welfare online PHP training,Help PHP learners grow quickly!</p> </div> <div id="wjcelcm34c" class="footermid"> <a href="http://ipnx.cn/about/us.html">About us</a> <a href="http://ipnx.cn/about/disclaimer.html">Disclaimer</a> <a href="http://ipnx.cn/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="c8zgi" class="pl_css_ganrao" style="display: none;"><wbr id="c8zgi"><sup id="c8zgi"><bdo id="c8zgi"></bdo></sup></wbr><label id="c8zgi"><em id="c8zgi"><del id="c8zgi"><sub id="c8zgi"></sub></del></em></label><td id="c8zgi"></td><pre id="c8zgi"><del id="c8zgi"><sup id="c8zgi"></sup></del></pre><strong id="c8zgi"></strong><sup id="c8zgi"></sup><em id="c8zgi"><dfn id="c8zgi"><center id="c8zgi"></center></dfn></em><strike id="c8zgi"></strike><xmp id="c8zgi"></xmp><big id="c8zgi"><source id="c8zgi"><label id="c8zgi"><pre id="c8zgi"></pre></label></source></big><video id="c8zgi"><tt id="c8zgi"></tt></video><strong id="c8zgi"><th id="c8zgi"></th></strong><dl id="c8zgi"><legend id="c8zgi"><strong id="c8zgi"></strong></legend></dl><output id="c8zgi"></output><table id="c8zgi"><option id="c8zgi"><ins id="c8zgi"></ins></option></table><tr id="c8zgi"></tr><ins id="c8zgi"><xmp id="c8zgi"><tr id="c8zgi"></tr></xmp></ins><strong id="c8zgi"></strong><abbr id="c8zgi"></abbr><i id="c8zgi"><strong id="c8zgi"></strong></i><wbr id="c8zgi"></wbr><abbr id="c8zgi"></abbr><strike id="c8zgi"></strike><u id="c8zgi"></u><dl id="c8zgi"></dl><strong id="c8zgi"><abbr id="c8zgi"></abbr></strong><strong id="c8zgi"><mark id="c8zgi"></mark></strong><cite id="c8zgi"></cite><table id="c8zgi"></table><fieldset id="c8zgi"><nobr id="c8zgi"><acronym id="c8zgi"></acronym></nobr></fieldset><thead id="c8zgi"><legend id="c8zgi"></legend></thead><address id="c8zgi"></address><legend id="c8zgi"><abbr id="c8zgi"></abbr></legend><label id="c8zgi"></label><pre id="c8zgi"></pre><output id="c8zgi"><pre id="c8zgi"><menuitem id="c8zgi"></menuitem></pre></output><button id="c8zgi"></button><blockquote id="c8zgi"></blockquote><abbr id="c8zgi"><button id="c8zgi"><delect id="c8zgi"><pre id="c8zgi"></pre></delect></button></abbr><dl id="c8zgi"></dl><thead id="c8zgi"><tbody id="c8zgi"><wbr id="c8zgi"></wbr></tbody></thead><s id="c8zgi"><cite id="c8zgi"></cite></s><em id="c8zgi"><dfn id="c8zgi"><center id="c8zgi"></center></dfn></em><center id="c8zgi"></center><meter id="c8zgi"></meter><em id="c8zgi"><dfn id="c8zgi"></dfn></em><menu id="c8zgi"></menu><del id="c8zgi"><sub id="c8zgi"><tfoot id="c8zgi"><rt id="c8zgi"></rt></tfoot></sub></del><fieldset id="c8zgi"><input id="c8zgi"><small id="c8zgi"><abbr id="c8zgi"></abbr></small></input></fieldset><tr id="c8zgi"><em id="c8zgi"><dfn id="c8zgi"></dfn></em></tr><object id="c8zgi"></object><legend id="c8zgi"><s id="c8zgi"><code id="c8zgi"></code></s></legend><label id="c8zgi"><th id="c8zgi"><kbd id="c8zgi"><acronym id="c8zgi"></acronym></kbd></th></label><rp id="c8zgi"></rp><sup id="c8zgi"><bdo id="c8zgi"></bdo></sup><b id="c8zgi"></b><rt id="c8zgi"></rt><small id="c8zgi"></small><optgroup id="c8zgi"></optgroup><legend id="c8zgi"><s id="c8zgi"><bdo id="c8zgi"></bdo></s></legend><p id="c8zgi"></p><big id="c8zgi"><source id="c8zgi"></source></big><pre id="c8zgi"><fieldset id="c8zgi"><pre id="c8zgi"></pre></fieldset></pre><acronym id="c8zgi"><delect id="c8zgi"><legend id="c8zgi"><ol id="c8zgi"></ol></legend></delect></acronym><option id="c8zgi"></option><big id="c8zgi"></big><xmp id="c8zgi"><tr id="c8zgi"><cite id="c8zgi"></cite></tr></xmp><video id="c8zgi"><small id="c8zgi"><sup id="c8zgi"></sup></small></video><label id="c8zgi"></label><menuitem id="c8zgi"><center id="c8zgi"><dl id="c8zgi"></dl></center></menuitem><pre id="c8zgi"><samp id="c8zgi"><tbody id="c8zgi"><dl id="c8zgi"></dl></tbody></samp></pre><dfn id="c8zgi"><center id="c8zgi"><dl id="c8zgi"><legend id="c8zgi"></legend></dl></center></dfn><small id="c8zgi"></small><th id="c8zgi"><kbd id="c8zgi"><font id="c8zgi"><meter id="c8zgi"></meter></font></kbd></th><cite id="c8zgi"><menu id="c8zgi"><style id="c8zgi"><table id="c8zgi"></table></style></menu></cite><object id="c8zgi"><style id="c8zgi"></style></object><delect id="c8zgi"></delect><b id="c8zgi"><address id="c8zgi"><strike id="c8zgi"></strike></address></b><mark id="c8zgi"></mark><object id="c8zgi"></object><b id="c8zgi"></b><button id="c8zgi"></button><dd id="c8zgi"></dd><blockquote id="c8zgi"><menuitem id="c8zgi"><center id="c8zgi"><th id="c8zgi"></th></center></menuitem></blockquote><abbr id="c8zgi"><button id="c8zgi"><delect id="c8zgi"></delect></button></abbr><cite id="c8zgi"></cite><optgroup id="c8zgi"><li id="c8zgi"><samp id="c8zgi"><pre id="c8zgi"></pre></samp></li></optgroup><dfn id="c8zgi"></dfn><span id="c8zgi"><thead id="c8zgi"></thead></span><strike id="c8zgi"></strike><tr id="c8zgi"></tr><wbr id="c8zgi"><fieldset id="c8zgi"><style id="c8zgi"><code id="c8zgi"></code></style></fieldset></wbr><track id="c8zgi"></track><abbr id="c8zgi"></abbr><menuitem id="c8zgi"><strike id="c8zgi"></strike></menuitem><listing id="c8zgi"><abbr id="c8zgi"><button id="c8zgi"><samp id="c8zgi"></samp></button></abbr></listing><center id="c8zgi"><tfoot id="c8zgi"><legend id="c8zgi"><label id="c8zgi"></label></legend></tfoot></center><label id="c8zgi"><small id="c8zgi"></small></label><output id="c8zgi"></output><del id="c8zgi"><dfn id="c8zgi"><center id="c8zgi"><dl id="c8zgi"></dl></center></dfn></del></div> </html>