不使用imagecreate在PHP中生成大型透明GIF

不使用imagecreate在PHP中生成大型透明GIF,php,performance,gif,lzw,Php,Performance,Gif,Lzw,出于内存/性能原因,我需要在不使用imagecreate()或ImageCreateTureColor()的情况下生成自定义大小的透明GIF。 我需要图像尽可能小,因此我不希望使用GCT,而只使用指定透明度的GCE,例如200x200px图像,如下所示: 47 49 46 38 39 61 - GIF89a C8 00 - 200px C8 00 - 200px 00 - No GCT 00 00 21 F9 - Graphic Control Extension 04 01 0A 00 01

出于内存/性能原因,我需要在不使用imagecreate()或ImageCreateTureColor()的情况下生成自定义大小的透明GIF。 我需要图像尽可能小,因此我不希望使用GCT,而只使用指定透明度的GCE,例如200x200px图像,如下所示:

47 49 46 38 39 61 - GIF89a
C8 00 - 200px
C8 00 - 200px
00 - No GCT
00 00 
21 F9 - Graphic Control Extension
04 01 0A 00 01 - colour #1 is transparent (I've seen this work on a 1x1 transparent GIF also without GCT)
00  - section separator
2C - image block
00 00 00 00 - block start position x=0, y=0
C8 00 C8 00 - block width and height, actually the image size
00 - section separator
? - image data follows
00 - section separator
3B - image end
2C - image block
00 00 00 00 - block start position x=0, y=0
01 00 01 00 - block width and height, actually the image size
到目前为止,我可以生成上面的GIF结构,但我遇到的问题是我需要创建LZW编码的数据。 对于工作正常的1x1透明像素图像,我看到以下字节:

02 - LZW minimum code size
02 - LZW data length
4C 01 - actual LZW data
首先,我怀疑这是如何解码的。这是否意味着LZW映射表有3位代码?如果是,它如何映射到字节


有人能解释或提供一个代码片段,为任意宽度x高度的透明GIF生成LZW数据吗?

最后,我将该块保留为1x1透明块,它在所有浏览器中都有效。 使用此方法,还需要将块大小保持为1 x 1,如下所示:

47 49 46 38 39 61 - GIF89a
C8 00 - 200px
C8 00 - 200px
00 - No GCT
00 00 
21 F9 - Graphic Control Extension
04 01 0A 00 01 - colour #1 is transparent (I've seen this work on a 1x1 transparent GIF also without GCT)
00  - section separator
2C - image block
00 00 00 00 - block start position x=0, y=0
C8 00 C8 00 - block width and height, actually the image size
00 - section separator
? - image data follows
00 - section separator
3B - image end
2C - image block
00 00 00 00 - block start position x=0, y=0
01 00 01 00 - block width and height, actually the image size