Save a "Bilevel" TIFF image ?

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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

To generate a bilevel image, add
  • MagickSetImageType(wand, BilevelType);
just before you call MagickWriteImage();
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

We tried this program with ImageMagick 6.3.0 and produced a bilevel group4-compressed TIFF image:

Code: Select all

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

int main(int argc,char **argv)
{
#define ThrowWandException(wand) \
{ \
  char \
    *description; \
 \
  ExceptionType \
    severity; \
 \
  description=MagickGetException(wand,&severity); \
  (void) fprintf(stderr,"%s %s %ld %s\n",GetMagickModule(),description); \
  description=(char *) MagickRelinquishMemory(description); \
  exit(-1); \
}

  MagickBooleanType
    status;

  MagickWand
    *magick_wand;

  /*
    Read an image.
  */
  MagickWandGenesis();
  magick_wand=NewMagickWand();  
  status=MagickReadImage(magick_wand,"image.gif");
  if (status == MagickFalse)
    ThrowWandException(magick_wand);
  /*
    Write as a bilvel group4-compressed TIFF image.
  */
  MagickSetImageType(magick_wand,BilevelType);
  MagickSetImageCompression(magick_wand,Group4Compression);
  status=MagickWriteImages(magick_wand,"image.tif",MagickTrue);
  if (status == MagickFalse)
    ThrowWandException(magick_wand);
  magick_wand=DestroyMagickWand(magick_wand);
  MagickWandTerminus();
  return(0);
}
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Post by el_supremo »

[EDIT: I'm using ImageMagick 6.3.0 10/14/06 Q8 binary]
I've been playing with the original code and I also get problems. It produces a TIF which crashes PSP X. When I identify the TIF, it has 3 colours:

Code: Select all

  Histogram:
        16: none                                          #000000FF
     94000: white                                         #FFFFFF00
    155984: rgba(255,255,255,0)                           #FFFFFFFF
  Colormap: 2
         0: black                                         #00000000
         1: white                                         #FFFFFF00
I've tried Magick's most recent code and that works but adding the Annotate blows it up again.
Try adding this code immediately before the MagickSetImageType:

Code: Select all

{
	DrawingWand *dw;
	PixelWand *pw;
	pw = NewPixelWand();
	PixelSetColor(pw,"black");
	dw = NewDrawingWand();
   DrawSetFont(dw, "Arial");
   DrawAnnotation(dw, 10, 10, "test");
   MagickDrawImage(magick_wand, dw);
   dw = DestroyDrawingWand(dw);
   pw = DestroyPixelWand(pw);
}
and if that doesn't cause problems then change the MagickReadImage filename to:

Code: Select all

http://members.shaw.ca/el_supremo/animate-2.gif
When I use this image and Annotate it, PSPX shows the output GIF as a black image with white spots down one side.
Also, change the output name to image.png and do a verbose identify. The type is GrayScaleMatte instead of Bilevel. If you just create a plain, white image, change it to Bilevel and write it as PNG, the output will be Bilevel.

Pete
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

Looks like you want to remove the alpha channel. Instead of MagickSetImageType() use:
  • MagickSetImageMatte(magick_wand,MagickFalse);
    MagickQuantizeImage(magick_wand,2,GRAYColorspace,0,MagickFalse,MagickFalse);
Post Reply