Converting Magickwand to Group 4 TIFF and CCITT compression gives an uncompressed image
Attempting to convert a 24 bpp bitmap to black and white TIFF with CCITT group 4 compression. The result is a 1 bpp TIFF image as expected, but not compressed.
I am using FreePascal which has magickwand bindings and the status is never MagickFalse:
MagickWandGenesis;
wand := NewMagickWand;
try
status := MagickReadImage(wand,PChar(InputFile));
if (status = MagickFalse) then HandleError;
status := MagickSetImageFormat(wand,'TIFF');
if (status = MagickFalse) then HandleError;
// convert to black & white/lineart
status := MagickSetImageType(wand,BilevelType);
if (status = MagickFalse) then HandleError;
// Group4Compression seems defined as 4 which
// apparently doesn't match imagemagick source. Bug:
//http://mantis.freepascal.org/view.php?id=26723
status := MagickSetImageCompression(wand,CompressionType(7)); //was Group4Compression
if (status = MagickFalse) then HandleError;
// Apparently set(image)compresionquality and
// stripimage are necessary to actually compress
status := MagickSetImageCompressionQuality(wand,0);
if (status = MagickFalse) then HandleError;
status := MagickStripImage(wand);
if (status = MagickFalse) then HandleError;
status := MagickWriteImage(wand,PChar(OutputFile));
if (status = MagickFalse) then HandleError;
finally
wand := DestroyMagickWand(wand);
end;
MagickWandTerminus;
Original image http://filehorst.de/d/bmqjzDuB
Original (faulty) source code of the program at http://filehorst.de/d/bluhjivq
Original (erroneous) output image at http://filehorst.de/d/bhlbjHgp
What am I doing wrong?
Edit: Allowed; got an off-site solution: the CompressionType enumeration in the FreePascal bindings is probably out of date - Group4Compression was 4 (IIRC), while it should be 7.
I will give a bounty to Mark Setchel as his answer was a necessary part of the solution. Source code above, updated with the correct version.
source to share
At least with the PHP version, it seems that setting the compression type doesn't actually compress the image - see below comments here .
It also shows that in all the examples I have found that you must then call MagickSetImageCompressionQuality()
and StripImage()
for the actual compression - see. Here .
source to share