Magick.NET icon indicating copy to clipboard operation
Magick.NET copied to clipboard

Compression Group4 and Fax has no effect for tiff.

Open t246246 opened this issue 8 years ago • 7 comments

Prerequisites

  • [x] I have written a descriptive issue title
  • [x] I have verified that I am using the latest version of Magick.NET
  • [x] I have searched open and closed issues to ensure it has not already been reported

Description

Using ImageMagick, it is easy to create Group4/Fax compressed tiff: % magick logo: -compress Group4 tmp.tif % magick logo: -compress Fax tmp.tif But the following Magick.NET program (in Steps to Reproduce) does not compress the file: It prints: LZW Zip RLE NoCompression NoCompression NoCompression

Steps to Reproduce

using System;
using System.IO;
using ImageMagick;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string outFile = "./tmp.tif";
            foreach (var c in new CompressionMethod[]
            {
                CompressionMethod.LZW,
                CompressionMethod.Zip,
                CompressionMethod.RLE,
                CompressionMethod.Group4,
                CompressionMethod.Fax,
                CompressionMethod.NoCompression
            }) {
                MagickReadSettings settings = new MagickReadSettings();
                using (var image = new MagickImage("logo:", settings))
                {
                    image.Format = MagickFormat.Tiff;
                    image.Settings.Compression = c;
                    image.Write(outFile);
                }
                using (var image = new MagickImage(outFile))
                {
                    Console.WriteLine(image.Compression);
                }
                File.Delete(outFile);
            }
        }
    }
}

System Configuration

  • Magick.NET version: 7.7.0 Q16 AnyCPU
  • Environment (Operating system, version and so on): Windows 7 64bit
  • Additional information:

t246246 avatar Sep 10 '18 04:09 t246246

It looks like you found the same bug that has been reported here: https://github.com/ImageMagick/ImageMagick/issues/1297. Will publish a new release soon to resolve this issue. Thanks for the detailed report. I will make sure I use that in a unit test.

dlemstra avatar Sep 10 '18 04:09 dlemstra

I just published Magick.NET 7.8.0.0 that includes a fix for your issue.

dlemstra avatar Sep 22 '18 19:09 dlemstra

This will show up in IM 7.0.8-12, I hope?

Jmuccigr avatar Sep 22 '18 20:09 Jmuccigr

@Jmuccigr Yes it will. And that will probably be released this weekend.

dlemstra avatar Sep 22 '18 20:09 dlemstra

Thank you. Now (in version 7.8.0.0), it works. But if I add image.SetAttribute("colorspace:auto-grayscale", "false"); i.e.

using (var image = new MagickImage("logo:", settings))
{
    image.SetAttribute("colorspace:auto-grayscale", "false");
    image.Format = MagickFormat.Tiff;
    image.Settings.Compression = c;
    image.Write(outFile);
}

it still outputs NoCompression for Fax and Group4. (I also tried with "off" instead of "false", result is the same.)

Oddly, "true" or "on" respect compression. This behaviour is inconsistent with command line usage:

C:\>magick --version
Version: ImageMagick 7.0.8-12 Q16 x64 2018-09-23 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Visual C++: 180040629
Features: Cipher DPC HDRI Modules OpenMP
Delegates (built-in): bzlib cairo flif freetype gslib heic jng jp2 jpeg lcms lqr lzma openexr pangocairo png ps raw rsvg tiff webp xml zlib

C:\>magick logo: -define colorspace:auto-grayscale=on -compress fax a.tif
C:\>magick logo: -define colorspace:auto-grayscale=off -compress fax b.tif
C:\>magick logo: -compress fax c.tif
C:\>magick identify -format "%C\n" a.tif b.tif c.tif
Fax
Fax
Fax

t246246 avatar Sep 25 '18 02:09 t246246

When you set colorspace:auto-grayscale to false you disable automatic conversion to grayscale that is required for Fax compression. And your ImageMagick command is not entirely correct. You will need to do this:

I:\>magick -version
Version: ImageMagick 7.0.8-12 Q16 x64 2018-09-23 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Visual C++: 191526730
Features: Debug Cipher DPC HDRI OpenCL OpenMP
Delegates (built-in): bzlib cairo flif freetype gslib heic jng jp2 jpeg lcms lqr lzma openexr pangocairo png ps raw rsvg tiff webp xml zlib

I:\>magick logo: -set colorspace:auto-grayscale on -compress fax a.tif
I:\>magick logo: -set colorspace:auto-grayscale false -compress fax b.tif
I:\>magick logo: -compress fax c.tif
I:\>magick identify -format "%C\n" a.tif b.tif c.tif
Fax
None
Fax

dlemstra avatar Sep 28 '18 10:09 dlemstra

Thank you. I understand auto-grayscale false and Fax/Group4 have some kind of contradiction, but I had thought both -define and -set are valid setting: https://www.imagemagick.org/discourse-server/viewtopic.php?t=28453#p126332 , but guessing from current document, https://www.imagemagick.org/script/command-line-options.php#define , using -define for this purpose for tiff is not proper.

t246246 avatar Sep 28 '18 10:09 t246246