這期內容當中小編將會給大家帶來有關利用PHP怎么對用戶上傳的圖片進行過濾,文章內容豐富且以專業的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
示例 下載
我在phpclasses.org上面偶然發現一個很有用的,由Bakr Alsharif開發的可以幫助開發者基于皮膚像素點來檢測圖片裸照的類文件.
它會分析在一張圖片的不同部分使用的顏色,并決定其是否匹配人類皮膚顏色的色調.
作為分析的結果,他會返回一個反映圖片包含裸露的可能性的分值.
此外,他還可以輸出被分析的圖片,上面對使用給定顏色的膚色的像素進行了標記.
當前它可以對PNG,GIF和JPEG圖片進行分析.
下面展示了如何使用這個PHP類.
讓我們先從包含裸體過濾器,nf.php文件開始.
include ('nf.php');接下來,創建一個新的名叫ImageFilter的類,然后把它放到一個叫做$filter的變量中.
$filter = new ImageFilter;
獲取圖片的分值并將其放到一個$score變量中.
$score = $filter -> GetScore($_FILES['img']['tmp_name']);
如果圖片分值大于或等于60%,那就展示一條(告警)消息.
if($score >= 60){
/*Message*/
}下面是所有的PHP代碼:
<?php
/*Include the Nudity Filter file*/
include ('nf.php');
/*Create a new class called $filter*/
$filter = new ImageFilter;
/*Get the score of the image*/
$score = $filter -> GetScore($_FILES['img']['tmp_name']);
/*If the $score variable is set*/
if (isset($score)) {
/*If the image contains nudity, display image score and message. Score value if more than 60%, it is considered an adult image.*/
if ($score >= 60) {
echo "Image scored " . $score . "%, It seems that you have uploaded a nude picture.";
/*If the image doesn't contain nudity*/
} else if ($score < 0) {
echo "Congratulations, you have uploaded an non-nude image.";
}
}
?>標記語言
我們可以使用一個基礎的HTML表單上傳圖片.
<form method="post" enctype="multipart/form-data" action="<?php echo $SERVER['PHP_SELF'];?> "> Upload image: <input type="file" name="img" id="img" /> <input type="submit" value="Sumit Image" /> </form>
上述就是小編為大家分享的利用PHP怎么對用戶上傳的圖片進行過濾了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。