Home  >  Article  >  Backend Development  >  How to read the height, width, frame number and background color of a flash file in PHP_PHP Tutorial

How to read the height, width, frame number and background color of a flash file in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 09:55:35900browse

How to use PHP to read the background color of the flash file’s height and width frames

This example describes how PHP reads the background color of the flash file’s height and width frames. Share it with everyone for your reference.

The specific implementation method is as follows:

The code is as follows:

 /*

Example:

$file = '/data/ad_files/5/5.swf';

 $flash = new flash();

$flash = $flash->getswfinfo($file);

echo "

The width and height of the file are: ".$flash["width"].":".$info["height"];

echo "

The file version is ".$flash["version"];

echo "

The number of file frames is ".$flash["framecount"];

echo "

The file frame rate is ".$flash["framerate"];

echo "

The file background color is ".$flash["bgcolor"];

 */

class flash

 {

// Whether to return the background color

public $need_back_color = false ;

//Whether to return version

public $need_version = false ;

// Whether to return the frame rate

public $need_framerate = false ;

// Whether to return the number of frames

public $need_framecount = false ;

public function __construct()

 {

 }

public function getswfinfo( $filename )

 {

 if ( file_exists($filename) ) {

//echo "File modification time:".date("m d y h:i:s.", filemtime($filename))."

 ";

 } else {

//echo "The target file does not exist!";

return array( "error" => $filename ) ;

 }

//Open file

 $rs = fopen($filename,"r");

//Read file data

 $str = fread( $rs , filesize( $filename ) ) ;

 ///

 if($str[0] == "f")

 {

 //echo "

The file is an unzipped file: ";

 } else {

 $first = substr($str,0,8);

 $last = substr($str,8);

//

 $last = gzuncompress($last);

//

 $str = $first . $last ;

 $str[0] = "f";

 //echo "

Decompressed file information: ";

 }

$info = $this->getinfo( $str );

 fclose ( $rs ) ;

return $info;

 }

private function mydecbin($str,$index)

 {

 $fbin = decbin(ord($str[$index]));

while(strlen($fbin)<8)$fbin="0".$fbin;

return $fbin;

 }

private function colorhex($data)

 {

 $tmp = dechex($data);

 if ( strlen($tmp)<2 ) {

 $tmp='0' . $tmp ;

 }

return $tmp;

 }

private function getinfo( $str )

 {

//Convert to binary

 $fbin = $this->mydecbin( $str , 8 ) ;

// Calculate the unit length of rec

 $slen = bindec( substr( $fbin , 0 , 5 ) );

// Calculate the byte where rec is located

 $recsize = $slen * 4 5 ;

 $recsize = ceil( $recsize / 8 ) ;

//rec binary

 $recbin = $fbin;

 for( $i = 9; $i < $recsize 8; $i )

 {

$recbin .= $this->mydecbin( $str ,$i );

 }

//rec data

 $rec = array();

 for( $i = 0 ; $i < 4 ; $i )

 {

 $rec[] = bindec( substr( $recbin , 5 $i * $slen , $slen ) ) / 20;

 }

 if ( $this->need_back_color ) {

//Background color

 for( $i = $recsize 12; $i < strlen ( $str ) ; $i )

 {

 if ( ord( $str[$i] ) == 67 && ord( $str[$i 1] ) == 2 )

 {

 $bgcolor = $this->colorhex(ord($str[$i 2])).$this->colorhex(ord($str[$i 3])).$this->colorhex (ord($str[$i 4]));

break;

 }

 }

 }

 if ( $this->need_version ) {

//Version

 $version = ord( $str[3] );

 }

 if ( $this->need_framerate ) {

// Frame rate

 $framerate = ord( $str[$recsize 8] ) / 256 ord( $str[$recsize 9] ) ;

 }

 if ( $this->need_framecount ) {

// Frame number

 $framecount = ord( $str[$recsize 11] ) * 256 ord( $str[$recsize 10] );

 }

return array ( "bgcolor" => $bgcolor ,

 "version" => $version ,

 "framerate" => $framerate ,

 "framecount" => $framecount ,

'width'=>$rec[1],

'height'=>$rec[3]

 );

 }

 }

 ?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/991642.htmlTechArticleHow to read the height, width, frame number and background color of a flash file using php. This article explains how to read the height and width of a flash file using php. Frame number background color method. Share it with everyone for your reference. Specific implementation method...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn