<?php /** * Flash Header reader * Alessandro Crugnola (sephiroth) * alessandro@sephiroth.it * http://www.sephiroth.it * * Read the SWF header informations and return an * associative array with the property of the SWF File * * @param input string file * @returns array * * * How to use * ------------------------------------- * $f = new FlashHeader("flash.swf"); * $result = $f->getimagesize(); * print_r($result); * ------------------------------------- * */ class FlashHeader{ var $version; var $filetype; var $bitpos; var $cur; var $pos; var $rect; var $framerate; var $length; var $compression = 0; var $point = 0; var $isValid = 0; /** * @method FlashHeader * @type constructor * @param string file */ function FlashHeader($buffer){ $this->buffer = $buffer; $fp = @fopen($this->buffer,"rb"); $head = @fread($fp, 3); if($head == "CWS"){ /* zlib */ fseek($fp,0); $data = fread($fp,8); 非常棒的一个方法,使用php程序可以读取swf文件的头部信息,如大小、播放版本、 播放速率、帧数和舞台大小等,似乎可以在以后的blog程序中自动获取swf文件的大小而不用手动设 定大小了。 引用地址:http://www.sephiroth.it 程序实现如下: ___FCKpd___0data = gzuncompress(fread($fp, filesize($buffer))); $data = $data . 非常棒的一个方法,使用php程序可以读取swf文件的头部信息, 如大小、播放版本、播放速率、帧数和舞台大小等,似乎可以在以后的blog程序中自动获取swf文件 的大小而不用手动设定大小了。 引用地址:http://www.sephiroth.it 程序实现如下: ___FCKpd___0data; $this->data = $data; $this->compression = 1; $this->isValid = 1; } else if ($head == "FWS"){ fseek($fp,0); $this->data = fread($fp, filesize($buffer)); $this->isValid = 1; } else { $this->isValid = 0; } @fclose($fp); } /** * @method getimagesize * @type public * @description read the file informations */ function getimagesize(){ if(!$this->isValid){ return false; } $this->filetype = $this->read(3); $this->version = $this->readbyte(); $l = $this->read(4); $this->filelength = filesize($this->buffer); $this->rect = $this->readRect(); $this->framerate = unpack(’vrate’,$this->read(2)); $this->framerate = $this->framerate[’rate’]/256; $this->framecount = $this->readshort(); return array( "zlib-compression"=> $this->compression, "fileType" => $this->filetype, "version" => $this->version, "fileSize" => $this->filelength, "frameRate" => $this->framerate, "frameCount" => $this->framecount, "movieSize" => $this->rect ); } /* read */ function read($n){ $ret = substr($this->data, $this->point, $this->point + $n); $this->point += $n; return $ret; } /* read short */ function readshort(){ $pack = unpack(’vshort’,$this->read(2)); return $pack[’short’]; } /* read byte */ function readByte(){ $ret = unpack("Cbyte",$this->read(1)); return $ret[’byte’]; } /* read Rect */ function readRect(){ $this->begin(); $l = $this->readbits(5); $xmin = $this->readbits($l)/20; $xmax = $this->readbits($l)/20; $ymin = $this->readbits($l)/20; $ymax = $this->readbits($l)/20; $rect = new Rect($xmax, $ymax); return $rect->__str__(); } /* incpos */ function incpos(){ $this->pos += 1; if($this->pos>8){ $this->pos = 1; $this->cur = $this->readbyte(); } } /* readbits */ function readbits($nbits){ $n = 0; $r = 0; while($n < $nbits){ $r = ($r<<1) + $this->getbits($this->pos); $this->incpos(); $n += 1; } return $r; } /* getbits */ function getbits($n){ return ($this->cur>>(8-$n))&1; } /* begin */ function begin(){ $this->cur = $this->readbyte(); $this->pos = 1; } } /** * class Rect * store the size values into an associative array */ class Rect{ function Rect($x2,$y2){ $this->xmax = $x2; $this->ymax = $y2; $this->value = $this->__str__(); } function __str__(){ $ret = array($this->xmax, $this->ymax); $ret["width"] = $this->xmax; $ret["height"] = $this->ymax; return $ret; } } /* end */ ?> |
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |