Skip to content

Commit 38365a4

Browse files
committed
Add support for reading GIFs without colormap
Cf. <libgd/libgd@fc38677>. Closes GH-17364.
1 parent 91384e5 commit 38365a4

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ PHP NEWS
2222
images). (cmb)
2323
. Ported fix for libgd 223 (gdImageRotateGeneric() does not properly
2424
interpolate). (cmb)
25+
. Added support for reading GIFs without colormap to bundled libgd. (Andrew
26+
Burley, cmb)
2527

2628
- Intl:
2729
. Fixed bug GH-11874 (intl causing segfault in docker images). (nielsdos)

ext/gd/libgd/gd_gif_in.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,10 @@ gdImagePtr gdImageCreateFromGifCtx(gdIOCtxPtr fd) /* {{{ */
244244
BitSet(buf[8], INTERLACE), &ZeroDataBlock);
245245
} else {
246246
if (!haveGlobalColormap) {
247-
gdImageDestroy(im);
248-
return 0;
247+
// Still a valid gif, apply simple default palette as per spec
248+
ColorMap[CM_RED][1] = 0xff;
249+
ColorMap[CM_GREEN][1] = 0xff;
250+
ColorMap[CM_BLUE][1] = 0xff;
249251
}
250252
ReadImage(im, fd, width, height,
251253
ColorMap,

ext/gd/tests/gif_nocolormaps.gif

37 Bytes
Loading

ext/gd/tests/gif_nocolormaps.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
A GIF without any Global or Local color tables is still decoded
3+
--EXTENSIONS--
4+
gd
5+
--FILE--
6+
<?php
7+
$im = imagecreatefromgif(__DIR__ . "/gif_nocolormaps.gif");
8+
var_dump($im instanceof GdImage);
9+
?>
10+
--EXPECT--
11+
bool(true)

0 commit comments

Comments
 (0)