Split multipage TIF,TIFF images into individual images and RETAIN original filename after conversion.

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
NikhilV
Posts: 2
Joined: 2017-02-21T05:39:15-07:00
Authentication code: 1151

Split multipage TIF,TIFF images into individual images and RETAIN original filename after conversion.

Post by NikhilV »

Hi All,

I have a set of Multi Page TIF image files, which I am trying to split into individual images. I have tried using convert, which does the trick, but does not give me an option to retain the original file name.

Example:

A.TIF - Original File (10 Pages)

I use :
Convert *.tif %d.tif

Output: 10 different images are created with the file names(0.tif, 1.tif,2.tif,3.tif, 4.tif,5.tif, 6.tif, 7.tif, 8.tif, 9.tif)

The above output would be perfect for me only if I could retain the original file name after conversion/splitting.

Desired output:

10 different images with filenames ( A_1.tif, A_2.tif, A_3.tif, A_4.tif, A_5.tif, A_6.tif, A_7.tif, A_8.tif, A_9.tif, A_10.if)

I have several multi page tif files that I would like to convert, and retain their original file names. I cannot type the filename everytime I run the command.

Here is a sample multi page tif file if required -- http://www.nightprogrammer.org/wp-uploa ... xample.tif


Any help on this is much appreciated.

Thanks in advance !!

PS: I have looked through the forums, googled a lot, tried Mogrify instead, but nothing seems to help.
- Mogrify is not able to split the files, rather it makes the same file 10 times larger.
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Split multipage TIF,TIFF images into individual images and RETAIN original filename after conversion.

Post by GeeMack »

NikhilV wrote: 2017-02-21T06:02:56-07:00Desired output:

10 different images with filenames ( A_1.tif, A_2.tif, A_3.tif, A_4.tif, A_5.tif, A_6.tif, A_7.tif, A_8.tif, A_9.tif, A_10.if)
Try this...

Code: Select all

convert A.tif -set filename:f "%[t]_%[fx:t+1]" +adjoin "%[filename:f].tif"
That should break the input file into multiple TIF images, each starting with the name of the input file, followed by an underscore, followed by incremental numbers starting with one, and ending with the ".tif" extension.
NikhilV
Posts: 2
Joined: 2017-02-21T05:39:15-07:00
Authentication code: 1151

Re: Split multipage TIF,TIFF images into individual images and RETAIN original filename after conversion.

Post by NikhilV »

Hi GeeMack,

Thank you for your prompt response. The solution works really well for my requirement, with a minor issue.

The below code gives works well if I use A.tif in it.

Code: Select all

convert A.tif -set filename:f "%[t]_%[fx:t+1]" +adjoin "%[filename:f].tif"
What I tried:

Code: Select all

convert *.tif -set filename:f "%[t]_%[fx:t+1]" +adjoin "%[filename:f].tif"
I renamed the same file to A.tif, B.tif, C.tif and tried the above code; it gives me the following output.

A.tif : A_1.tif , A_2.tif, A_3.tif, A_4.tif, A_5.tif, A_6.tif, A_7.tif, A_8.tif, A_9.tif, A_10.tif
B.tif : B_11.tif , B_12.tif, B_13.tif, B_14.tif, B_15.tif, B_16.tif, B_17.tif, B_18.tif, B_19.tif, B_20.tif
C.tif : C_21.tif , C_22.tif, C_23.tif, C_24.tif, C_25.tif, C_26.tif, C_27.tif, C_28.tif, C_29.tif, C_30.tif


Is there a way to start the number increment from 1 for each file?

Example:

A.tif : A_1.tif , A_2.tif, A_3.tif, A_4.tif, A_5.tif, A_6.tif, A_7.tif, A_8.tif, A_9.tif, A_10.tif
B.tif : B_1.tif , B_2.tif, B_3.tif, B_4.tif, B_5.tif, B_6.tif, B_7.tif, B_8.tif, B_9.tif, B_10.tif
C.tif : C_1.tif , C_2.tif, C_3.tif, C_4.tif, C_5.tif, C_6.tif, C_7.tif, C_8.tif, C_9.tif, C_10.tif


Thank you in advance :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Split multipage TIF,TIFF images into individual images and RETAIN original filename after conversion.

Post by fmw42 »

try adding -scene 0 after reading the *.tif, but I am not sure even that will work.

You may have to write a script loop over each image and run it as in your first case. If so the script loop will depend upon your OS. Please always provide your IM version and platform/OS.

Code: Select all

convert Image.tif -set filename:f "%[t]_%[fx:t+1]" +adjoin "%[filename:f].tif"
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Split multipage TIF,TIFF images into individual images and RETAIN original filename after conversion.

Post by fmw42 »

fmw42 wrote: 2017-02-22T00:55:49-07:00 try adding -scene 0 after reading the *.tif, but I doubt even that will work.

You may have to write a script loop over each image and run it as in your first case. If so the script loop will depend upon your OS. Please always provide your IM version and platform/OS.

Code: Select all

convert Image.tif -set filename:f "%[t]_%[fx:t+1]" +adjoin "%[filename:f].tif"
Post Reply