Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compression Group4 and Fax has no effect for tiff. #307

Closed
t246246 opened this issue Sep 10, 2018 · 7 comments

Comments

Projects
None yet
3 participants
@t246246
Copy link

commented Sep 10, 2018

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am using the latest version of Magick.NET
  • 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:

@dlemstra dlemstra added the bug label Sep 10, 2018

@dlemstra

This comment has been minimized.

Copy link
Owner

commented Sep 10, 2018

It looks like you found the same bug that has been reported here: ImageMagick/ImageMagick#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

This comment has been minimized.

Copy link
Owner

commented Sep 22, 2018

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

@Jmuccigr

This comment has been minimized.

Copy link

commented Sep 22, 2018

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

@dlemstra

This comment has been minimized.

Copy link
Owner

commented Sep 22, 2018

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

@t246246

This comment has been minimized.

Copy link
Author

commented Sep 25, 2018

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
@dlemstra

This comment has been minimized.

Copy link
Owner

commented Sep 28, 2018

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
@t246246

This comment has been minimized.

Copy link
Author

commented Sep 28, 2018

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.

@dlemstra dlemstra closed this Oct 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.