用PHP分析GIF动画图片

walkingcoder.gif
Phpclasses有一个生成GIF动态图片的Class当下来试试,很好用。

gift89a.gif

看了看源代码,只是实现了GIF图片的简单叠加,而如果要想做到分析GIF动态图片,做到将GIF动态图片拆分,甚至修改后重新生成新的GIF动态图片。看来还是要从分析GIF89a规范入手。在了解GIF89a的编码规则以后,还需要了解LZW,因为GIF采用的是这种LZW的无损压缩的算法。
这是我总结的GIF89a规则,希望有时间好好研究一下:

=========================
The Definition of the GIF Format allows for a Data Stream to contain:

* Header
Signature: ‘GIF’ => 3 bytes: 0×47 0×49 0×46
Version: ‘89a’ => 3 bytes: 0×38 0×39 0×61
* the Logical Screen Descriptor
Logical Screen Width: unsigned 2 bytes
Logical Screen Height: unsigned 2 bytes
Packed Fields:
Global Color Table Flag 1 Bit
Color Resolution 3 Bits
Sort Flag 1 Bit
Size of Global Color Table 3 Bits
Background Color Index: 1 byte
Pixel Aspect Ratio: 1 byte (Aspect Ratio = (Pixel Aspect Ratio + 15) / 64)
* a Global Color Table
size: 3 x 2^(Size of Global Color Table+1).
* Image Descriptor
Image Separator: 1 byte => 0×2C
Image Left Position: unsigned 2 bytes
Image Top Position: unsigned 2 bytes
Image Width: unsigned 2 bytes
Image Height: unsigned 2 bytes
Packed Fields:
Local Color Table Flag 1 Bit (if 1, follow immediately after this Image Descriptor.)
Interlace Flag 1 Bit
Sort Flag 1 Bit
Reserved 2 Bits
Size of Local Color Table 3 Bits
* Table Based Image Data
LZW Minimum Code Size: 1 byte
Image Data (Data Sub-blocks)

//////////Animated Control Start
* Graphic Control Extension.
Extension Introducer: 1 byte => 0×21
Graphic Control Label: 1 byte => 0xF9
Block Size: 1 byte
Packed Fields:
Reserved 3 Bits
Disposal Method 3 Bits (Recommendations: 0)
User Input Flag 1 Bit (Recommendations: 0)
Transparent Color Flag 1 Bit
Delay Time: unsigned 2 bytes
Transparent Color Index: 1 byte
Block Terminator: 1 byte
//////////Animated Control End

* Comment Extension.
Extension Introducer: 1 byte => 0×21
Comment Label: 1 byte => 0xFE
Comment Data (Data Sub-blocks): using the 7-bit ASCII character set
(each of size at most 255 bytes and at least 1 byte)
do not interfere with Control or Data blocks
Block Terminator: 1 byte => 0×00
* Plain Text Extension (Skip)
* Application Extension (Skip)
* Trailer: 1 byte => 0×3B

===========================

Tags: , ,

Social Bookmark: Delicious   Digg   Facebook   Stumblue   Technorati  

No Comments

No comments yet.

Comments RSS

Leave a comment

Comment spam protected by SpamBam