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

MagickImageCollection.Flatten on TIFF Image - Error - Improper Image Header #1200

Closed
tenderlovingzulu opened this issue Jun 16, 2022 · 1 comment
Milestone

Comments

@tenderlovingzulu
Copy link

Magick.NET version

Magick.NET-Q16-AnyCPU Version 11.10 and up

Environment (Operating system, version and so on)

Windows 10 Pro Version 10.0.19043 Build 19043

Description

I receive an "improper image header" error message when flattening a multi-layered TIFF image (see below). I then downgraded to v.9.0.0. I re-ran my code, upgraded to the next version, and repeated the process, until I discovered the error is generated in all versions starting at 11.1.0. Another discovery: when there are 2 or more masking channels, the error is triggered, BUT when there is only 1 masking channel, the file flattens successfully. (This might point to where in the code this bug was introduced.)

SOURCE TIFF TEST FILE (file too large to attach here)

[https://vrxwestus.blob.core.windows.net/vrxstudios-downloads/layered.tif]

ERROR MESSAGE

ImageMagick.MagickCorruptImageErrorException
HResult=0x80131500
Message=improper image header [path-to-tiff-file]' @ error/psd.c/ReadPSDLayersInternal/2021 Source=Magick.NET-Q16-AnyCPU StackTrace: at ImageMagick.MagickImageCollection.NativeMagickImageCollection.ReadFile(IMagickSettings1 settings)
at ImageMagick.MagickImageCollection..ctor(String fileName)
at Program.

$(String[] args) in [path-to-program.cs]:line 10

CODE

using (MagickImage img = new MagickImageCollection("[path-to-tiff-file]").Flatten())
{
img.Depth = 8;
img.Settings.Compression = CompressionMethod.LZW;
img.RemoveProfile("8bim");
img.RemoveProfile("psd:additional-info");
img.HasAlpha = false;
img.Label = "Background";
img.Write(Path.Combine([path-to-tiff-file-flattened]));
}

Steps to Reproduce

  1. Created a .NET 6.0 console app in VS 2022 Community
  2. Started with Magick.NET-Q16-AnyCPU Version 9.0.0.
  3. Ran the above code.
  4. Upgraded to the next version of Magick.NET.
  5. Repeat steps 3 and 4 for every version up to the current version (at the writing of this issue, this was 11.2.0).
@dlemstra dlemstra added this to the 11.2.1 milestone Jun 19, 2022
@dlemstra
Copy link
Owner

This is related to ImageMagick adding support for more channels in the TIFF image format. This broke reading the (PSD) layers and I added a patch to resolve this in the next release of Magick.NET.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants