网站地图    收藏   

主页 > php专栏 > php应用 >

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

来源:自学PHP网    时间:2014-11-27 22:16 作者: 阅读:

[导读] ?php/*示例:$file=#39;/data/ad_files/5/5.swf#39;;$flash=newflash();$flash=$flash-getswfinfo($file);echo文件的宽高是:.$flash[......

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

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

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论