Page 1 of 1

BlobToImage fails with .ico file

Posted: 2007-12-12T17:11:39-07:00
by rmagick
This is Version: ImageMagick 6.3.7 12/09/07 Q16 http://www.imagemagick.org on Kubuntu Gutsy Gibbon.

Here's the input image: Image.

In the test program, BlobToImage returns NULL and does not set any values in the exception structure. If I store "ICO" in the image_info->magick field, BlobToImage returns a correct image. Please let me know if you need any other information.

Code: Select all

/*
Call BlobToImage on a .ICO file

gcc `Magick-config --cflags --cppflags` icoblob.c `Magick-config --ldflags --libs` -o icoblob
*/


#include <stdio.h>
#include <time.h>
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
#include "magick/MagickCore.h"


int main()
{
  Image *image;
  ImageInfo *image_info;
  FILE *img;
  char blob[4000];
  size_t length;
  ExceptionInfo exception;

  MagickCoreGenesis("icoblob" ,MagickFalse);

  image_info = CloneImageInfo(NULL);
  if (!image_info)
  {
    puts("CloneImageInfo failed.");
    exit(1);
  }

  img = fopen("favicon.ico", "r");
  length = fread(blob, 1, sizeof(blob), img);
  if (ferror(img))
  {
      puts("ferror");
      exit(1);
  }

  GetExceptionInfo(&exception);

  // strcpy(image_info->magick, "ico");
  image = BlobToImage(image_info,  blob, (size_t)length, &exception);

  DestroyImageInfo(image_info);

  if (!image)
  {
    puts("No image returned.");
    if (exception.severity > UndefinedException)
    {
        printf("%s: %s", exception.reason, exception.description);
    }
  }
  else
  {
      puts("Got an image");
      DestroyImage(image);
  }

  DestroyMagick();

  exit(0);
  }

Re: BlobToImage fails with .ico file

Posted: 2007-12-12T19:13:39-07:00
by magick
ICO images do not have a magic number so you must explicitly set the image magick or filename. We added an exception reason in the event the image has no magic number and neither the image magick or filename is set.

Re: BlobToImage fails with .ico file

Posted: 2007-12-12T19:54:25-07:00
by rmagick
Interesting. Thanks!