当前位置:首页 > PHP教程 > php高级应用 > 列表

php读取flash文件高宽帧数背景颜色代码

发布:smiling 来源: PHP粉丝网  添加日期:2014-09-08 20:35:55 浏览: 评论:0 
  1. <?php 
  2. /* 
  3. 示例: 
  4.   $file = '/data/ad_files/5/5.swf'; 
  5.   $flash = new flash(); 
  6.   $flash = $flash->getswfinfo($file); 
  7.   echo " 
  8. 文件的宽高是:".$flash["width"].":".$info["height"]; 
  9.   echo " 
  10. 文件版本是".$flash["version"]; 
  11.   echo " 
  12. 文件帧数量是".$flash["framecount"]; 
  13.   echo " 
  14. 文件帧速率是".$flash["framerate"]; 
  15.   echo " 
  16. 文件背景颜色是".$flash["bgcolor"]; 
  17. */ 
  18. class flash 
  19. { 
  20.   //是否返回背景色 
  21.   public $need_back_color = false ; 
  22.    
  23.   //是否返回版本 
  24.   public $need_version = false ; 
  25.    
  26.   //是否返回帧速率 
  27.   public $need_framerate = false ; 
  28.    
  29.   //是否返回帧数量 
  30.   public $need_framecount = false ; 
  31.   public function __construct()  
  32.   { 
  33.   } 
  34.   public function getswfinfo( $filename ) 
  35.   { 
  36.     if ( file_exists($filename) ) { 
  37.        //echo "文件的修改时间:".date("m d y h:i:s.", filemtime($filename))." 
  38. "; 
  39.     } else { 
  40.        //echo "目标文件不存在!"; 
  41.        return array( "error" => $filename ) ; 
  42.     } 
  43.     //打开文件 
  44.     $rs = fopen($filename,"r"); 
  45.      
  46.     //读取文件的数据 
  47.     $str = fread( $rs , filesize( $filename ) ) ; 
  48.     /// 
  49.     if($str[0] == "f") 
  50.     { 
  51.        //echo " 
  52. 文件已是解压缩的文件:"; 
  53.     } else { 
  54.        $first = substr($str,0,8); 
  55.        $last = substr($str,8); 
  56.        // 
  57.        $last = gzuncompress($last); 
  58.        // 
  59.        $str = $first . $last ; 
  60.        $str[0] = "f"; 
  61.        //echo " 
  62. 解压缩后的文件信息:"; 
  63.     } 
  64.     $info = $this->getinfo( $str ); 
  65.     fclose ( $rs ) ; 
  66.     return $info; 
  67.   } 
  68.   private function mydecbin($str,$index) 
  69.   { 
  70.     $fbin = decbin(ord($str[$index])); 
  71.     while(strlen($fbin)<8)$fbin="0".$fbin; 
  72.     return $fbin; 
  73.   } 
  74.   private function colorhex($data) 
  75.   { 
  76.     $tmp = dechex($data); 
  77.     if ( strlen($tmp)<2 ) { 
  78.       $tmp='0' . $tmp ; 
  79.     } 
  80.     return $tmp; 
  81.   } 
  82.   private function getinfo( $str ) 
  83.   { 
  84.     //换算成二进制 
  85.     $fbin = $this->mydecbin( $str , 8 ) ; 
  86.      
  87.     //计算rec的单位长度 
  88.     $slen = bindec( substr( $fbin , 0 , 5 ) ); 
  89.      
  90.     //计算rec所在的字节 
  91.     $recsize = $slen * 4 + 5 ; 
  92.     $recsize = ceil( $recsize / 8 ) ; 
  93.     //rec的二进制 
  94.     $recbin = $fbin ; 
  95.     for( $i = 9 ; $i < $recsize + 8 ; $i++ ) 
  96.     { 
  97.        $recbin .= $this->mydecbin( $str ,$i ); 
  98.     } 
  99.     //rec数据 
  100.     $rec = array(); 
  101.     for( $i = 0 ; $i < 4 ; $i++ ) 
  102.     { 
  103.        $rec[] = bindec( substr( $recbin , 5 + $i * $slen , $slen ) ) / 20 ; 
  104.     } 
  105.      
  106.     if ( $this->need_back_color ) { 
  107.       //背景颜色 
  108.       for( $i = $recsize + 12 ; $i < strlen ( $str ) ; $i ++ ) 
  109.       { 
  110.          if ( ord( $str[$i] ) == 67 && ord( $str[$i+1] ) == 2 ) 
  111.          { 
  112.           $bgcolor = $this->colorhex(ord($str[$i+2])).$this->colorhex(ord($str[$i+3])).$this->colorhex(ord($str[$i+4])); 
  113.           break; 
  114.          } 
  115.       } 
  116.     } 
  117.      
  118.     if ( $this->need_version ) { 
  119.       //版本 
  120.       $version = ord( $str[3] ); 
  121.     } 
  122.     if ( $this->need_framerate ) { 
  123.       //帧速率 
  124.       $framerate = ord( $str[$recsize + 8] ) / 256 + ord( $str[$recsize + 9] ) ; 
  125.     } 
  126.     if ( $this->need_framecount ) {     
  127.       //帧数量 
  128.       $framecount = ord( $str[$recsize + 11] ) * 256 + ord( $str[$recsize + 10] );//开源代码phpfensi.com 
  129.     } 
  130.      
  131.     return  array ( "bgcolor" => $bgcolor , 
  132.             "version" => $version ,  
  133.             "framerate" => $framerate ,  
  134.             "framecount" => $framecount ,  
  135.             'width'=>$rec[1], 
  136.             'height'=>$rec[3] 
  137.             ); 
  138.   } 
  139. } 
  140. ?> 

Tags: php读取flash flash高宽帧数

分享到: