imagemagicktifflayer

export tif layers with offset


Take a multilayered tif image and describe it:

magick identify multilayered.tif

Here are the layers:

multilayered.tif[1] TIFF 476x620 476x620+747+90 8-bit sRGB 236.532MiB 0.040u 0:00.039
...
multilayered.tif[307] TIFF 449x623 449x623+1002+87 8-bit sRGB 0.010u 0:00.009
...
multilayered.tif[316] TIFF 505x623 505x623+12+87 8-bit sRGB 0.010u 0:00.009

I would like to export each layer as a png file, placed according to offset values in a 1451x710 wider transparent area, which is the multilayered.tif size.

I manage to get every layer but in their smallest extend

magick multilayered.tif -set filename:MYFILE %l %[filename:MYFILE].png

Then I need to compose 300 times with

composite multilayered_0001.png wider_area.png -geometry +747+90 multilayered_0001.png

Is there a one step magick way ?


Solution

  • This is a Windows CLI command that should read the multilayer input and create an output image from each layer, with dimensions of 1451x710 pixels, and placing the contents of each layer at the offsets from the TIF.

    magick multilayer.tif -set filename:0 %[t] -background none ^
       -extent 1451x710-%[fx:s.page.x]-%[fx:s.page.y] %[filename:0]-%03d.png
    

    That creates an image from each TIF layer, and uses ImageMagick's FX expressions to read the offsets and place the outputs on a transparent background at those locations.

    The output files are named from the input name and numbered with three digits and leading zeros.

    For a *nix OS you'll need to change the continued-line caret "^" to a backslash "\", and possibly isolate the FX expressions inside double-quotes "%[fx:...]" if any characters are special in your shell.