Transparency ignored in GIF

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
canavan
Posts: 23
Joined: 2013-02-18T10:12:03-07:00
Authentication code: 6789

Transparency ignored in GIF

Post by canavan »

While the usual browsers display a transparent background for the GIF image Image, imagemagick displays (or generates an output image with) a black background. Additionally, convert (tested with 6.8.9-9 and 7.0.2-9) complains:

Code: Select all

convert: invalid colormap index `/tmp/pages.gif' @ error/colormap-private.h/ConstrainColormapIndex/34.
canavan
Posts: 23
Joined: 2013-02-18T10:12:03-07:00
Authentication code: 6789

Re: Transparency ignored in GIF

Post by canavan »

convert -debug mentions: Coder (GIF) generated an image despite an error (425), notify the developers

Code: Select all

2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Configure convert[3933]: utility.c/ExpandFilenames/943/Configure
  Command line: convert {/tmp/pages.gif} {-debug} {all} {-}
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Configure convert[3933]: configure.c/GetConfigureOptions/688/Configure
  Searching for configure file: "/home/canavan/FIT/trunk/share/ImageMagick-7/magic.xml"
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Configure convert[3933]: configure.c/GetConfigureOptions/688/Configure
  Searching for configure file: "/home/canavan/FIT/trunk/lib/ImageMagick-7.0.2//config-Q16/magic.xml"
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Configure convert[3933]: configure.c/GetConfigureOptions/688/Configure
  Searching for configure file: "/home/canavan/FIT/trunk/conf/ImageMagick-7/magic.xml"
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Configure convert[3933]: configure.c/GetConfigureOptions/688/Configure
  Searching for configure file: "/home/canavan/FIT/trunk/share/doc/ImageMagick-7/magic.xml"
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Configure convert[3933]: configure.c/GetConfigureOptions/688/Configure
  Searching for configure file: "/home/canavan/.config/ImageMagick/magic.xml"
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Configure convert[3933]: magic.c/LoadMagicCache/853/Configure
  Loading magic configure file "/home/canavan/FIT/trunk/conf/ImageMagick-7/magic.xml" ...
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Policy convert[3933]: policy.c/IsRightsAuthorized/583/Policy
  Domain: Path; rights=Read; pattern="/tmp/pages.gif" ...
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Blob convert[3933]: blob.c/OpenBlob/2587/Blob
    read 3 magic header bytes
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Cache convert[3933]: cache.c/DestroyPixelCache/950/Cache
  destroy 
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Policy convert[3933]: policy.c/IsRightsAuthorized/583/Policy
  Domain: Coder; rights=Read; pattern="GIF" ...
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Policy convert[3933]: policy.c/IsRightsAuthorized/583/Policy
  Domain: Path; rights=Read; pattern="/tmp/pages.gif" ...
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Blob convert[3933]: blob.c/OpenBlob/2587/Blob
    read 3 magic header bytes
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Resource convert[3933]: resource.c/AcquireMagickResource/314/Resource
  Width: 18B/0P/214.7MP
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Resource convert[3933]: resource.c/AcquireMagickResource/314/Resource
  Height: 16B/0P/214.7MP
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Pixel convert[3933]: pixel.c/LogPixelChannels/4324/Pixel
  /tmp/pages.gif[4]
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Pixel convert[3933]: pixel.c/LogPixelChannels/4408/Pixel
    0: red (update)
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Pixel convert[3933]: pixel.c/LogPixelChannels/4408/Pixel
    1: green (update)
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Pixel convert[3933]: pixel.c/LogPixelChannels/4408/Pixel
    2: blue (update)
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Pixel convert[3933]: pixel.c/LogPixelChannels/4408/Pixel
    3: index (copy)
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Pixel convert[3933]: pixel.c/SetPixelChannelMask/6268/Pixel
  /tmp/pages.gif[07ffffff]
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Pixel convert[3933]: pixel.c/LogPixelChannels/4324/Pixel
  /tmp/pages.gif[4]
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Pixel convert[3933]: pixel.c/LogPixelChannels/4408/Pixel
    0: red (update)
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Pixel convert[3933]: pixel.c/LogPixelChannels/4408/Pixel
    1: green (update)
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Pixel convert[3933]: pixel.c/LogPixelChannels/4408/Pixel
    2: blue (update)
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Pixel convert[3933]: pixel.c/LogPixelChannels/4408/Pixel
    3: index (copy)
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Resource convert[3933]: resource.c/AcquireMagickResource/314/Resource
  Area: 2.3KB/2.3KB/24.955GB
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Resource convert[3933]: resource.c/AcquireMagickResource/314/Resource
  Memory: 2.3KB/2.25KiB/11.621GiB
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Cache convert[3933]: cache.c/OpenPixelCache/3517/Cache
  open /tmp/pages.gif[0] (Heap Memory, 18x16x4 2.25KiB)
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Locale convert[3933]: locale.c/GetLocaleOptions/829/Locale
  Searching for locale file: "/home/canavan/FIT/trunk/share/ImageMagick-7/locale.xml"
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Locale convert[3933]: locale.c/GetLocaleOptions/829/Locale
  Searching for locale file: "/home/canavan/FIT/trunk/lib/ImageMagick-7.0.2//config-Q16/locale.xml"
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Locale convert[3933]: locale.c/GetLocaleOptions/829/Locale
  Searching for locale file: "/home/canavan/FIT/trunk/conf/ImageMagick-7/locale.xml"
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Locale convert[3933]: locale.c/GetLocaleOptions/829/Locale
  Searching for locale file: "/home/canavan/FIT/trunk/share/doc/ImageMagick-7/locale.xml"
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Locale convert[3933]: locale.c/GetLocaleOptions/829/Locale
  Searching for locale file: "/home/canavan/.config/ImageMagick/locale.xml"
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Configure convert[3933]: locale.c/LoadLocaleCache/1181/Configure
  Loading locale configure file "/home/canavan/FIT/trunk/share/ImageMagick-7/locale.xml" ...
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Locale convert[3933]: locale.c/GetLocaleOptions/829/Locale
  Searching for locale file: "/home/canavan/FIT/trunk/share/ImageMagick-7/english.xml"
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Locale convert[3933]: locale.c/GetLocaleOptions/829/Locale
  Searching for locale file: "/home/canavan/FIT/trunk/lib/ImageMagick-7.0.2//config-Q16/english.xml"
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Locale convert[3933]: locale.c/GetLocaleOptions/829/Locale
  Searching for locale file: "/home/canavan/FIT/trunk/conf/ImageMagick-7/english.xml"
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Locale convert[3933]: locale.c/GetLocaleOptions/829/Locale
  Searching for locale file: "/home/canavan/FIT/trunk/share/doc/ImageMagick-7/english.xml"
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Locale convert[3933]: locale.c/GetLocaleOptions/829/Locale
  Searching for locale file: "/home/canavan/.config/ImageMagick/english.xml"
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Configure convert[3933]: locale.c/LoadLocaleCache/1181/Configure
  Loading locale configure file "/home/canavan/FIT/trunk/share/ImageMagick-7/english.xml" ...
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Exception convert[3933]: colormap-private.h/ConstrainColormapIndex/34/Exception
  invalid colormap index `/tmp/pages.gif'
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Exception convert[3933]: colormap-private.h/ConstrainColormapIndex/34/Exception
  invalid colormap index `/tmp/pages.gif'
[...]
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Exception convert[3933]: colormap-private.h/ConstrainColormapIndex/34/Exception
  invalid colormap index `/tmp/pages.gif'
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Cache convert[3933]: cache.c/DestroyPixelCache/950/Cache
  destroy 
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Exception convert[3933]: constitute.c/ReadImage/571/Exception
  Coder (GIF) generated an image despite an error (425), notify the developers
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Policy convert[3933]: policy.c/IsRightsAuthorized/583/Policy
  Domain: Coder; rights=Write; pattern="GIF" ...
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Policy convert[3933]: policy.c/IsRightsAuthorized/583/Policy
  Domain: Path; rights=Write; pattern="-" ...
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Cache convert[3933]: cache.c/DestroyPixelCache/950/Cache
  destroy /tmp/pages.gif[0]
2016-10-06T12:06:42+02:00 0:00.000 0.000u 7.0.2 Resource convert[3933]: resource.c/RelinquishMagickResource/960/Resource
  Memory: 2.3KB/0B/11.621GiB
convert: invalid colormap index `/tmp/pages.gif' @ error/colormap-private.h/ConstrainColormapIndex/34.
GIF89a������䄄�!�,&����&Es�Ъ�:�}�H��n�P�皊��Ũ=��R;
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Transparency ignored in GIF

Post by fmw42 »

Please provide your exact command line and upload your image to some place such as dropbox.com and put the URL here so we can test with it.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Transparency ignored in GIF

Post by snibgo »

The image is in the OP. It is small, after the words "GIF image".

I suspect it has bad metadata, which some software silently ignores.
snibgo's IM pages: im.snibgo.com
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Transparency ignored in GIF

Post by glennrp »

It is a 2-bit GIF with 4 colors plus the transparent color; the transparent color is therefore out of range (note the "4c"):

Code: Select all

magick identify *.gif
pages.gif GIF 18x16 18x16+0+0 8-bit sRGB 4c 102B 0.000u 0:00.000
canavan
Posts: 23
Joined: 2013-02-18T10:12:03-07:00
Authentication code: 6789

Re: Transparency ignored in GIF

Post by canavan »

It doesn't surprise me that the image is not according to spec, however I'd prefer if Imagemagick were able to handle these Images more gracefully.

My primary problem is that at the moment, this kind of error is not detectable with PHP/imagick, and I've filed a separate bug report at https://bugs.php.net/bug.php?id=73263
Danack
Posts: 73
Joined: 2013-10-14T10:00:25-07:00
Authentication code: 6789

Re: Transparency ignored in GIF

Post by Danack »

Is there any way to detect this error when using the C api?

Trying to detect any error with the code below doesn't show up any errors.

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <wand/MagickWand.h>
    

int main(int argc,char **argv) {
    MagickWand *magick_wand;
    MagickBooleanType status;
    char *exception_text;
    ExceptionType severity;

    MagickWandGenesis();
    magick_wand = NewMagickWand();
    status = MagickReadImage(magick_wand, "./images/pages_invalid_gif.gif");

    if (status == MagickFalse) {
        printf("Failed to MagickReadImage");
        return -1;
    }
    exception_text = MagickGetException(magick_wand, &severity);

    if (exception_text == NULL) {
        printf("exception_text is NULL\n");
    }
    else {
        printf("exception_text is %s\n", exception_text);
    }
    
    printf("Severity is %d\n", severity);

    MagickSetImageFormat(magick_wand, "png");

    status = MagickWriteImages(magick_wand, "./73263.png", MagickTrue);
    if (status == MagickFalse) {
        printf("Failed to MagickWriteImages");
        return -1;
    }

    MagickWandTerminus();
 
    return(0);
}

Post Reply