php圖片搜索
Ⅰ php+vue.js怎麼用照片搜索相似照片
需要工具:電腦、橋慧瀏覽器、搜索引擎
一、首先選擇任意瀏覽器,點擊打開。
二、然後打開搜索,可以看到搜索框有一個照相機的小圖標。
三、點一下相機的小圖標,會提示拖拽一張照片或者上傳一張照片,這段坦個根據自己的情況選擇。
四、這里我們選擇上傳,選一握消桐張自己想找相似的圖片,雙擊圖片。
五、好了,這個時候就搜索出了圖片的來源和出處,還有類似的圖片。
Ⅱ php怎麼實現根據圖片搜索圖片功能
php愛好者 們很對php開發的追求是永不止步的,今天偶然想起來了 發下
php怎麼實現相似圖片的搜索呢?
其中的原理來解釋下
1、縮小尺寸。將圖片縮小到8×8的尺寸,總共64個像素。這一步的作用是去除圖片的細節,只保留結構、明暗等基本信息,摒棄不同尺寸、比例帶來的圖片差異。
2、簡化色彩。將縮小後的圖片,轉為64級灰度。也就是說,所有像素點總共只有64種顏色。
3、計算平均值。計算所有64個像素的灰度平均值。
4、比較像素的灰度。將每個像素的灰度,與平均值進行比較。大於或等於平均值,記為1;小於平均值,記為0。
5、計算哈希值。將上一步的比較結果,組合在一起,就構成了一個64位的整數,這就是這張圖片的指紋。組合的次序並不重要,只要保證所有圖片都採用同樣次序就行了。得到指紋以後,就可以對比不同的圖片,看看64位中有多少位是不一樣的。
使用代碼
hash($f);
}
return $isString ? $result[0] : $result;
}
public function checkIsSimilarImg($imgHash, $otherImgHash){
if (file_exists($imgHash) && file_exists($otherImgHash)){
$imgHash = $this->run($imgHash);
$otherImgHash = $this->run($otherImgHash);
}
if (strlen($imgHash) !== strlen($otherImgHash)) return false;
$count = 0;
$len = strlen($imgHash);
for($i=0;$i<$len;$i++){
if ($imgHash{$i} !== $otherImgHash{$i}){
$count++;
}
}
return $count <= (5 * $rate * $rate) ? true : false;
}
public function hash($file){
if (!file_exists($file)){
return false;
}
$height = 8 * $this->rate;
$width = 8 * $this->rate;
$img = imagecreatetruecolor($width, $height);
list($w, $h) = getimagesize($file);
$source = $this->createImg($file);
imageresampled($img, $source, 0, 0, 0, 0, $width, $height, $w, $h);
$value = $this->getHashValue($img);
imagedestroy($img);
return $value;
}
public function getHashValue($img){
$width = imagesx($img);
$height = imagesy($img);
$total = 0;
$array = array();
for ($y=0;$y<$height;$y++){
for ($x=0;$x<$width;$x++){
$gray = ( imagecolorat($img, $x, $y) >> 8 ) & 0xFF;
if (!is_array($array[$y])){
$array[$y] = array();
}
$array[$y][$x] = $gray;
$total += $gray;
}
}
$average = intval($total / (64 * $this->rate * $this->rate));
$result = '';
for ($y=0;$y<$height;$y++){
for ($x=0;$x<$width;$x++){
if ($array[$y][$x] >= $average){
$result .= '1';
}else{
$result .= '0';
}
}
}
return $result;
}
public function createImg($file){
$ext = $this->getFileExt($file);
if ($ext === 'jpeg') $ext = 'jpg';
$img = null;
switch ($ext){
case 'png' : $img = imagecreatefrompng($file);break;
case 'jpg' : $img = imagecreatefromjpeg($file);break;
case 'gif' : $img = imagecreatefromgif($file);
}
return $img;
}
public function getFileExt($file){
$infos = explode('.', $file);
$ext = strtolower($infos[count($infos) - 1]);
return $ext;
}
}
調用方式如下:
require_once "Imghash.class.php";
$instance = ImgHash::getInstance();
$result = $instance->checkIsSimilarImg('chenyin/IMG_3214.png', 'chenyin/IMG_3212.JPG');
如果$result值為true, 則表明2個圖片相似,否則不相似。
Ⅲ 求助,請給我一個基於PHP的圖片搜索網站的源碼,做畢業設計用,萬分感謝!
給你個思路,抓取下面的URL即可,把phpha換成你的搜索詞。
http://image..com/i?tn=image&word=phpha
抓取過來後正則分析下即可。
Ⅳ php有沒有簡單的方法識別兩張圖片是否相似/相同
理論上肯定是可以的。扮舉不過這應該是一個很高深的東西。所以,我只能給你我很粗淺的方法:
一:寫個函數,這個函數的主要功能是找出一張圖片上的主要顏色(代碼在最後面)
二:把一張圖片有GD庫分成9份(3*3)或更多薯備份,然後用第一個函數來取得每一份小圖的主要顏色。
三:比對這幾份小圖的顏色,看哪一份的顏色是你需要的。
如果你原數缺毀意,你也可以切很多份,比如10000份(100*100),然後計算這10000個顏色的中你需要的顏色的分布,找出你需要的區域。
$i=("image.jpg");
for($x=0;$x for($y=0;$y $rgb=($i,$x,$y); $r=($rgb<<16)&0xFF; $g=($rgb<<&0xFF; $b=$rgb&0xFF; $rTotal=$r; $gTotal=$g; $bTotal=$b; $total; } } $rAverage=round($rTotal/$total); $gAverage=round($gTotal/$total); $bAverage=round($bTotal/$total); Ⅳ PHP 通過圖片ID,查詢圖片對應的url並反饋頁面
具體報什麼錯配灶能提供一下嗎?建議看一稿賣嘩下你的表feelback有沒有你要查詢的這些欄位,沒有的話是會報錯的鍵行。
Ⅵ PHP網頁圖片搜索顯示
你這個問題是早族類似的文件遍歷問題; Ⅶ 用php 如何把某個盤中的所有圖片檢索出來
使用opendir遞歸打開根目錄已鏈槐碰經下面的子目錄,然明睜後棚談使用 glob函數直接glob("*.jpg") 枚舉.jpg這樣格式的文件,直接到數組裡面,很省事,思路如此!
Ⅷ 用PHP獲取HTML中的圖片地址並全部列出
<?php Ⅸ php 按條件搜索圖片,伺服器更新圖片後。客戶看到的還是更新前的
瀏覽器緩存的原因,可以通過在圖片地址後附加一個隨機值,每次載入圖片時,瀏覽器就會認為這是蔽凱一個新的請求而去服務區上讀取圖片,示做悄例: Ⅹ PHP如何實現搜索結果(或分類)下的圖片滾動瀏覽(如百度圖片一樣)
哈哈,你這個需求大部分都是javascript來完成的.
實現思路:
1,建立你的表單
2,當表單提交後,使用對文件遍歷的相關函數,對純睜轎你要做肆搜索的文件名進行顯示既可。
$test = '<p>444<img height="768" width="1024" alt="帶老亮" src="/uploadfiles/28/Tree.jpg" /></p><p>444<img height="768" width="1024" alt="" src="含空/uploadfiles/sf/Tree.jpg" /></p>
fsdafasdfasdfasdf
<p>444<img height="768" width="1024" alt="" src="/uploadfiles/28/elm.jpg" /></p><img height="768" width="1024" src="/uploadfiles/40/Tree.jpg" />
sdfasdfasdf<p>
<p>444<img height="768" width="1024" alt="" src="/uploadfiles/28/maple.jpg" /></p>
<img height="768" width="1024" src="/uploadfiles/40/Tree.jpg" />
sdf32414撒旦發是否
<p>444<img height="768" width="1024" alt="" src="/蠢寬uploadfiles/40/Tree.jpg" /><img height="768" src="/uploadfiles/40/Tree.jpg" /></p><img height="768" src="/uploadfiles/40/Tree.jpg" />tttt<img height="768" src="/uploadfiles/40/Tree.jpg" />';
preg_match_all("<img.*?src=\"(.*?.*?)\".*?>",$test,$match); //這里是關鍵
foreach($match[1] as $val){
echo basename($val);
echo "<br />";
}
?>
<img src="純並渣path/to/pic.jpg?r=<?php echo rand(1, 10000)" />
關於圖一的列表樣式,無非就是瀑布流滾動配合ajax到php後台取數據實現無限載入而已
插件都是現成的
http://www.17sucai.com/pins/4714.html
至於圖二就更簡單.無非是一個javascript的相冊插件,也用現成的,php就是按照插件的格式把數據循環出來即可
鑒於你可能比較菜,給你推薦這款插件吧 比較簡單 配置也有詳細說明
http://www.helloweba.com/view-blog-61.html