0
我需要圖像採集卡。我的意思是像Digg這樣的圖像採集卡,可以搜索其他頁面(包括YouTube,普通網站,經濟學家,......任何),獲得體面大小的圖像,如果選擇它,我可以將其上傳到我的服務器。Ajax圖像採集卡
有沒有人知道這個插件?
謝謝。
我需要圖像採集卡。我的意思是像Digg這樣的圖像採集卡,可以搜索其他頁面(包括YouTube,普通網站,經濟學家,......任何),獲得體面大小的圖像,如果選擇它,我可以將其上傳到我的服務器。Ajax圖像採集卡
有沒有人知道這個插件?
謝謝。
我不知道任何現成的庫。但我曾經需要一種快速的方法來從頁面中檢索「主要圖像」。我最好的猜測是隻獲得最大的文件大小。我使用PHP SimpleHTMLDom庫來輕鬆訪問該網站的<img>
標籤。
現在,這是代碼的主要部分,它返回給定頁面的最大圖像文件的URL。
希望你可以在此基礎上。
// Load the remote document
$html = file_get_html($url);
$largest_file_size=0;
$largest_file_url='';
// Go through all images of that page
foreach($html->find('img') as $element){
// Helper function to make absolute URLs from relative
$img_url=$this->InternetCombineUrl($url,$element->src);
// Try to get image file size info from header:
$header=array_change_key_case(get_headers($img_url, 1));
// Only continue if "200 OK" directly or after first redirect:
if($header[0]=='HTTP/1.1 200 OK' || @$header[1]=='HTTP/1.1 200 OK'){
if(!empty($header['content-length'])){
// If we were redirected, the second entry is the one.
// See http://us3.php.net/manual/en/function.filesize.php#84130
if(!empty($header['content-length'][1])){
$header['content-length']=$header['content-length'][1];
}
if($header['content-length']>$largest_file_size){
$largest_file_size=$header['content-length'];
$largest_file_url=$img_url;
}
}else{
// If no content-length-header is sent, we need to download the image to check the size
$tmp_filename=sha1($img_url);
$content = file_get_contents($img_url);
$handle = fopen(TMP.$tmp_filename, "w");
fwrite($handle, $content);
fclose($handle);
$filesize=filesize(TMP.$tmp_filename);
if($filesize>$largest_file_size){
$largest_file_size=$filesize;
$largest_file_url=$img_url;
unlink(TMP.$tmp_filename);
}
}
}
}
return $largest_file_url;
我會看看它。謝謝。 – denislexic 2011-04-20 10:42:45