Loving Coding & Visual Design
用PHP分析GIF动画图片
Phpclasses有一个生成GIF动态图片的Class,当下来试试,很好用。
看了看源代码,只是实现了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: 0x47 0x49 0x46
Version: '89a' => 3 bytes: 0x38 0x39 0x61
* 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 => 0x2C
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 => 0x21
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 => 0x21
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 => 0x00
* Plain Text Extension (Skip)
* Application Extension (Skip)
* Trailer: 1 byte => 0x3B
===========================
最 近 文 章
- 关于图片上传目录777权限的解决办法 - Mon, 10 Mar 2008 08:37:09 +0000
- Adsense推荐中等矩形 (300 x 250)来展示广告 - Wed, 05 Mar 2008 12:37:18 +0000
- google的工程哲学 - Tue, 04 Mar 2008 12:55:43 +0000
- 利用“301”HTTP头给网站更换域名 - Fri, 29 Feb 2008 02:07:05 +0000
- 话筒的烦恼 - Wed, 27 Feb 2008 16:33:39 +0000
- Windows批处理(BAT)技巧 - Wed, 27 Feb 2008 05:01:28 +0000
- GoogleMap推出静态地图引用服务 - Fri, 22 Feb 2008 05:39:50 +0000
- 二维条形码(2D BarCodes)技术 - Fri, 01 Feb 2008 09:50:35 +0000
- Compare Date with PERL - Mon, 28 Jan 2008 09:19:22 +0000
- Google催生更多千万、亿万富翁 - Fri, 25 Jan 2008 14:50:13 +0000