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

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
246246
Posts: 128
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

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

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

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.
Last edited by 246246 on 2017-09-11T17:41:20-07:00, edited 1 time in total.

User avatar
fmw42
Posts: 22091
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

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

Post by fmw42 » 2017-09-11T10:37:35-07:00

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.

snibgo
Posts: 9385
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo » 2017-09-11T11:20:20-07:00

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
snibgo's IM pages: im.snibgo.com

Post Reply