Page 1 of 1

How to create multipage tiff with keeping compression scheme in every page

Posted: 2017-09-11T05:19:47-07:00
by 246246

Code: Select all

$ magick -version
Version: ImageMagick 7.0.7-1 Q16 x64 2017-09-09 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 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 jng jp2 jpeg lcms lqr openexr pangocairo png ps rsvg tiff webp xml zlib
Here, I have a following file:
https://www.dropbox.com/s/y1hzh3kjkbvx9 ... x.tif?dl=1

Code: Select all

$ magick identify logo_mix.tif
logo_mix.tif[0] TIFF 640x480 640x480+0+0 1-bit Bilevel Gray 173172B 0.000u 0:00.001
logo_mix.tif[1] TIFF 640x480 640x480+0+0 2-bit Grayscale Gray 173172B 0.000u 0:00.000
logo_mix.tif[2] TIFF 640x480 640x480+0+0 8-bit Grayscale Gray 173172B 0.000u 0:00.000
logo_mix.tif[3] TIFF 640x480 640x480+0+0 8-bit sRGB 256c 173172B 0.000u 0:00.000
logo_mix.tif[4] TIFF 640x480 640x480+0+0 16-bit sRGB 173172B 0.000u 0:00.000

$ magick identify -format '%C\n' logo_mix.tif
Group4
LZW
LZW
LZW
Zip
When I create new file using the following command:

Code: Select all

$ magick convert logo_mix.tif[0] logo_mix.tif[4] logo_tmp.tif

$ magick identify logo_tmp.tif
logo_tmp.tif[0] TIFF 640x480 640x480+0+0 1-bit Bilevel Gray 14156B 0.000u 0:00.000
logo_tmp.tif[4] TIFF 640x480 640x480+0+0 1-bit Bilevel Gray 14156B 0.000u 0:00.000
5th page becomes 1-bit in a new file. It looks all the compression scheme becomes the one of the first image.

Code: Select all

$ magick identify -format '%C\n' logo_tmp.tif
Group4
Group4
So the question is are there any way to create multipage tiff keeping the compression scheme in each tiff page?

PS I know it can be done with tiffcp after separating it to pages, but I'd like to know if it is possible with ImageMagick's command line or some API in Magick.NET.

Re: How to create multipage tiff with keeping compression scheme in every page

Posted: 2017-09-11T10:37:35-07:00
by fmw42
This should work, but it does not in IM 6 or 7

Code: Select all

magick -respect-parenthesis \( logo_mix.tif[0] -depth 1 \) \( logo_mix.tif[4] -depth 16 \) new.tif

Code: Select all

magick identify new.tif
new.tif[0] TIFF 640x480 640x480+0+0 1-bit Bilevel Gray 14154B 0.000u 0:00.009
new.tif[4] TIFF 640x480 640x480+0+0 1-bit Bilevel Gray 14154B 0.000u 0:00.009

But this almost works for me in IM 7.0.7.0 Q16. Unfortunately, it does not preserve the 1-bit (bilevel) first page [0]

Code: Select all

magick -respect-parenthesis \( logo_mix.tif[0] -depth 1 \) \( logo_mix.tif[4] -depth 16 \) miff:- | magick - new.tif

Code: Select all

magick identify new.tif
new.tif[0] TIFF 640x480 640x480+0+0 8-bit Grayscale Gray 2.05129MiB 0.000u 0:00.000
new.tif[4] TIFF 640x480 640x480+0+0 16-bit sRGB 2.05129MiB 0.000u 0:00.000

So I think this is a bug.

Re: How to create multipage tiff with keeping compression scheme in every page

Posted: 2017-09-11T11:20:20-07:00
by snibgo
This is horrible behaviour, but I fear it may be the expected behaviour. It works fine if we reverse them, putting the sRGB image first:

Code: Select all

f:\web\im>%IM%convert logo_mix.tif -reverse x.tif

f:\web\im>%IM%identify x.tif
x.tif[4] TIFF 640x480 640x480+0+0 16-bit sRGB 163KB 0.031u 0:00.014
x.tif[5] TIFF 640x480 640x480+0+0 8-bit sRGB 256c 163KB 0.031u 0:00.014
x.tif[6] TIFF 640x480 640x480+0+0 8-bit Grayscale Gray 163KB 0.031u 0:00.014
x.tif[7] TIFF 640x480 640x480+0+0 2-bit Grayscale Gray 163KB 0.031u 0:00.014
x.tif[8] TIFF 640x480 640x480+0+0 1-bit Bilevel Gray 163KB 0.000u 0:00.000