php視頻縮略圖
㈠ 如何用php獲取主流視頻網站的縮略圖
給你說下大體的思路吧,正好也剛寫完個爬蟲。
首先,要爬取想要的視頻頁面,先要有能用代碼模擬出來整個登錄過程,(有些需要登陸後才能顯示的),這些包括以什麼形式訪問此頁面GET?POST?,當然這里POST需要加參數才能訪問,另外,最好還要把COOIKES值設置成固定的,這樣訪問才不容易被識別為異常訪問:(我用的是官方發行的一個類-Quest.php)
->實例化HTTP_ HTTP_Request("域名");
->聲明相應的請求;$req->setMethod(HTTP_REQUEST_METHOD_GET); $req->setMethod(HTTP_REQUEST_METHOD_POST);
->發送連接;$req->setURL("http://www..com");
->執行請求:$req->sendRequest();
->得到cookies:$cookies = $req->getResponseCookies();(傳給一個新的數組,在需要反復爬取的頁面盡量傳此cookies,需要登陸爬取的必反)
->清除post和cookies:$req->clearPostData(); $req->clearCookies(); (循環爬取時需要清除)
->添加post方法:$req->addPostData(name,value,false); 參數name,參數value;
->得到理想頁:$response = $req->getResponseBody();
->得到頭信息:$resHeader = $req->getResponseHeader();
->打開指定文件:$res = fopen("c:/love/forever.txt", 'w');
->寫入 :fwrite($res,$response); #寫入
->關閉指針:fclose($res);
我爬取的去文字信息,你要爬取對應視頻圖片直接抓取出來就行了--
你可以試下這個代碼,js:在隨便網頁地址欄輸入---javascript:Ai7Mg6P='';for%20(i7M1bQz=0;i7M1bQz<document.images.length;i7M1bQz++)
{Ai7Mg6P+='<img%20src='+document.images[i7M1bQz].src+'><br>'};if(Ai7Mg6P!=''){document.write('<center>'+Ai7Mg6P+'</center>');
void(document.close())}else{alert('No%20images!')}
加油!
㈡ php截取視頻第一幀 作為略縮圖,怎麼弄
你的這個需求是能實現的,事先的原理是:視頻網站的自定義視頻縮略圖功能,在這里以優酷視頻為例說明: 1、登錄賬號,進入到個人視頻中心,點擊視頻後面的編輯 2、選擇「自選封面」-然後開始播放視頻,在剛開始的地方,暫停視頻,然後點擊下面的截...
㈢ php創建縮略圖問題
其實PHP創建縮略圖就是在PHP在原圖片的基礎上創建一張新的圖片的過程,而用PHP創建圖像的過程一般分成四部:
第一步:創建一張畫布(只要是畫圖都需要一張畫布的)
第二步:在畫布畫東西(可以畫各種圖形,如長方形,直線,等等,也可以在畫布上寫字啥的,或者畫其他的圖形)
第三步:畫完圖之後,將圖片輸出,將圖片輸出到瀏覽器,在瀏覽器顯示出來,或者保存為一張新 的圖片(縮略圖一般是保存為圖片文件的)
第四步:因為創建畫布時打開了文件流,所以要關閉資源,節省內存。(個人覺得你可以這樣理解,打開了一畫布,把它鋪開了,畫完了就把畫布捲起來,收起來,不要佔著鋪的地方)
具體的代碼如下:(這段代碼來源於ThinkPHP的圖像類)
<?php
classThumb{
/**
*@paramstring$image原圖
*@paramstring$thumbname縮略圖文件名
*@paramstring$type圖像格式
*@paramstring$maxWidth寬度
*@paramstring$maxHeight高度
*/
staticcreate($img,$thumbname,$type='',$maxWidth=200,$maxHeight=50)
{
$info=getimagesize($img);//獲取原圖的圖像信息(長、寬、格式等)
if($info!==false){
$srcWidth=$info['width'];
$srcHeight=$info['height'];
$type=empty($type)?$info['type']:$type;
$type=strtolower($type);
$interlace=$interlace?1:0;
unset($info);
$scale=min($maxWidth/$srcWidth,$maxHeight/$srcHeight);//計算縮放比例
if($scale>=1){
//超過原圖大小不再縮略
$width=$srcWidth;
$height=$srcHeight;
}else{
//縮略圖尺寸
$width=(int)($srcWidth*$scale);
$height=(int)($srcHeight*$scale);
}
//載入原圖(在原圖的基礎上創建畫布,為第一步)
$createFun='ImageCreateFrom'.($type=='jpg'?'jpeg':$type);
if(!function_exists($createFun)){
returnfalse;
}
$srcImg=$createFun($image);
//第二步開始
//創建縮略圖
if($type!='gif'&&function_exists('imagecreatetruecolor'))
$thumbImg=imagecreatetruecolor($width,$height);
else
$thumbImg=imagecreate($width,$height);
//png和gif的透明處理byluofei614
if('png'==$type){
imagealphablending($thumbImg,false);//取消默認的混色模式(為解決陰影為綠色的問題)
imagesavealpha($thumbImg,true);//設定保存完整的alpha通道信息(為解決陰影為綠色的問題)
}elseif('gif'==$type){
$trnprt_indx=imagecolortransparent($srcImg);
if($trnprt_indx>=0){
//itstransparent
$trnprt_color=imagecolorsforindex($srcImg,$trnprt_indx);
$trnprt_indx=imagecolorallocate($thumbImg,$trnprt_color['red'],$trnprt_color['green'],$trnprt_color['blue']);
imagefill($thumbImg,0,0,$trnprt_indx);
imagecolortransparent($thumbImg,$trnprt_indx);
}
}
//復制圖片
if(function_exists("ImageCopyResampled"))
imageresampled($thumbImg,$srcImg,0,0,0,0,$width,$height,$srcWidth,$srcHeight);
else
imageresized($thumbImg,$srcImg,0,0,0,0,$width,$height,$srcWidth,$srcHeight);
//第三步:輸出圖像
//生成圖片
$imageFun='image'.($type=='jpg'?'jpeg':$type);
$imageFun($thumbImg,$thumbname);
//第四步:關閉畫布
imagedestroy($thumbImg);
imagedestroy($srcImg);
return$thumbname;
}
returnfalse;
}
}
?>
你使用的時候直接用:
requireThumb.class.php
$thumb=Thumb::create('s.jpg','thumb_s.jpg',100,50);
希望我的回答你能滿意
㈣ 求大神解釋下面php縮略圖代碼的詳細功能邏輯
1. 功能邏輯:
獲取原圖片大小 - 與設定的最大寬度、高度比較 - 得出圖像的縮放比例 - 根據縮放比例,算出生成縮略圖的新長寬數值 - 使用imageresampled或是imageresized函數最終生成圖像
2. 想改為縮略圖不變形該如何改?
如果想使縮略圖不變形,最重要的一點是等比縮放,也就是長度和寬度的縮放比例要一樣。
最簡便的辦法是修改以下兩句:
imageresized($thumbImg, $srcImg, 0, 0, $x, $y, $width, $height, $srcWidth,$srcHeight);
imageresampled($thumbImg, $srcImg, 0, 0, $x, $y, $width, $height, $srcWidth,$srcHeight);
$width, $height 這兩個參數保證與 $srcWidth,$srcHeight 同比就行了。
㈤ 如何用PHP獲取優酷、土豆、酷6、56等視頻網站的視頻縮略圖
方案1,
上那些網站,查看源代碼,從中找出那些視頻的鏈接地址,加到自己網頁里,
方案2
用PHP里的小偷工具
自己看著辦吧,你給的分也太少了
㈥ 能直接用的PHP生成縮略圖的程序(要求簡單)
<?php
/*構造函數-生成縮略圖+水印,參數說明:
$srcFile-圖片文件名,
$dstFile-另存文件名,
$markwords-水印文字,
$markimage-水印圖片,
$dstW-圖片保存寬度,
$dstH-圖片保存高度,
$rate-圖片保存品質*/
makethumb("a.jpg","b.jpg","50","50");
function makethumb($srcFile,$dstFile,$dstW,$dstH,$rate=100,$markwords=null,$markimage=null)
{
$data = GetImageSize($srcFile);
switch($data[2])
{
case 1:
$im=@ImageCreateFromGIF($srcFile);
break;
case 2:
$im=@ImageCreateFromJPEG($srcFile);
break;
case 3:
$im=@ImageCreateFromPNG($srcFile);
break;
}
if(!$im) return False;
$srcW=ImageSX($im);
$srcH=ImageSY($im);
$dstX=0;
$dstY=0;
if ($srcW*$dstH>$srcH*$dstW)
{
$fdstH = round($srcH*$dstW/$srcW);
$dstY = floor(($dstH-$fdstH)/2);
$fdstW = $dstW;
}
else
{
$fdstW = round($srcW*$dstH/$srcH);
$dstX = floor(($dstW-$fdstW)/2);
$fdstH = $dstH;
}
$ni=ImageCreateTrueColor($dstW,$dstH);
$dstX=($dstX<0)?0:$dstX;
$dstY=($dstX<0)?0:$dstY;
$dstX=($dstX>($dstW/2))?floor($dstW/2):$dstX;
$dstY=($dstY>($dstH/2))?floor($dstH/s):$dstY;
$white = ImageColorAllocate($ni,255,255,255);
$black = ImageColorAllocate($ni,0,0,0);
imagefilledrectangle($ni,0,0,$dstW,$dstH,$white);// 填充背景色
ImageCopyResized($ni,$im,$dstX,$dstY,0,0,$fdstW,$fdstH,$srcW,$srcH);
if($markwords!=null)
{
$markwords=iconv("gb2312","UTF-8",$markwords);
//轉換文字編碼
ImageTTFText($ni,20,30,450,560,$black,"simhei.ttf",$markwords); //寫入文字水印
//參數依次為,文字大小|偏轉度|橫坐標|縱坐標|文字顏色|文字類型|文字內容
}
elseif($markimage!=null)
{
$wimage_data = GetImageSize($markimage);
switch($wimage_data[2])
{
case 1:
$wimage=@ImageCreateFromGIF($markimage);
break;
case 2:
$wimage=@ImageCreateFromJPEG($markimage);
break;
case 3:
$wimage=@ImageCreateFromPNG($markimage);
break;
}
image($ni,$wimage,500,560,0,0,88,31); //寫入圖片水印,水印圖片大小默認為88*31
imagedestroy($wimage);
}
ImageJpeg($ni,$dstFile,$rate);
ImageJpeg($ni,$srcFile,$rate);
imagedestroy($im);
imagedestroy($ni);
}
?>
㈦ php怎樣截取視頻圖
用ffmpeg直接讀取網站的某個視頻,然後截取其中的某幀作為該視頻的縮略圖;讀取網站自身提供的視頻縮略圖。
獲取圖片路徑:
function get_youku_thumb($url) {
$content = file_get_contents($url);
preg_match( '/id="s_msn2".*?screenshot=(.*?)".?target=/', $content, $matchs );
return $matchs[1];
}
echo get_youku_thumb('視頻網址');
把過去的圖片WordPress的縮略圖,可以將獲取縮略圖的代碼做成shortcode,直接在文章中調用。也可以通過custom_field方式記錄視頻地址,在主循環中調用該函數獲得縮略圖,藉助timthumb.php等腳本生成緩存存放到本地,就不用每次都去讀網頁了。