Skip to content

Commit

Permalink
Add support for reading GIFs without colormap
Browse files Browse the repository at this point in the history
  • Loading branch information
cmb69 committed Jan 9, 2025
1 parent 91384e5 commit 38365a4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ PHP NEWS
images). (cmb)
. Ported fix for libgd 223 (gdImageRotateGeneric() does not properly
interpolate). (cmb)
. Added support for reading GIFs without colormap to bundled libgd. (Andrew
Burley, cmb)

- Intl:
. Fixed bug GH-11874 (intl causing segfault in docker images). (nielsdos)
Expand Down
6 changes: 4 additions & 2 deletions ext/gd/libgd/gd_gif_in.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,10 @@ gdImagePtr gdImageCreateFromGifCtx(gdIOCtxPtr fd) /* {{{ */
BitSet(buf[8], INTERLACE), &ZeroDataBlock);
} else {
if (!haveGlobalColormap) {
gdImageDestroy(im);
return 0;
// Still a valid gif, apply simple default palette as per spec
ColorMap[CM_RED][1] = 0xff;
ColorMap[CM_GREEN][1] = 0xff;
ColorMap[CM_BLUE][1] = 0xff;
}
ReadImage(im, fd, width, height,
ColorMap,
Expand Down
Binary file added ext/gd/tests/gif_nocolormaps.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions ext/gd/tests/gif_nocolormaps.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--TEST--
A GIF without any Global or Local color tables is still decoded
--EXTENSIONS--
gd
--FILE--
<?php
$im = imagecreatefromgif(__DIR__ . "/gif_nocolormaps.gif");
var_dump($im instanceof GdImage);
?>
--EXPECT--
bool(true)

0 comments on commit 38365a4

Please sign in to comment.