Page 1 of 1

Transparency ignored in GIF

Posted: 2016-10-06T02:46:16-07:00
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.

Re: Transparency ignored in GIF

Posted: 2016-10-06T03:08:04-07:00
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;

Re: Transparency ignored in GIF

Posted: 2016-10-06T08:43:57-07:00
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.

Re: Transparency ignored in GIF

Posted: 2016-10-06T09:14:09-07:00
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.

Re: Transparency ignored in GIF

Posted: 2016-10-06T11:01:01-07:00
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

Re: Transparency ignored in GIF

Posted: 2016-10-07T03:58:30-07:00
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

Re: Transparency ignored in GIF

Posted: 2016-12-20T15:44:33-07:00
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);
}