Image magic convert command creates more than one file

I executed below command to convert a .tif file to a .jpg file. But for some tif images it generates 3 jpg files when only one file is expected. One is the expected jpg file, one is the same image in a black background and the other is just a white image.

magick convert /<.tif image name> -intent relative -resize 1500x1500> -quality 95 -colorspace sRGB -strip -auto-orient /<output .jpg image name>

Does anyone know the reason for this? what property of the input file causing this? or is there a issue with the command?

magick convert /<.tif image> -intent relative -resize 1500x1500> -quality 95 -colorspace sRGB -strip -auto-orient /<output .jpg image> Expect this to give a single jpg image. But it gives 3 images for some input .tif images

Upvotes: 0

Views: 306

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207510

Just adding some meat to @GeeMack's comment...

TIFF files often contain multiple images - or IFDs as referred to in the documentation. These can represent many things, but the most common are:

  • a low-resolution, flattened preview image followed by a full-resolution image aimed at providing quick previews
  • multiple pages of longer documents
  • colour separations for printing
  • the many channels of multi/hyper-spectral images
  • the layers of a multi-layer images, e.g. Photoshop editing layers
  • images and their associated masks, or classes/categories/classifications
  • ... and so on.

A quick way to check what you have is with ImageMagick's identify command as that will produce a line for each image in the file, and you can often tell by the sizes, shapes and types of the layers which is a small preview and which is high resolution image, or that there are 242 channels of identical resolution images for a EO-1 hyperspectral imager.

magick identify IMAGE.TIF

Here's an example:

magick identify Prokudin-Gorskii.tif 
Prokudin-Gorskii.tif[0] TIFF 3702x3205 3702x3205+0+0 16-bit sRGB 134.955MiB 0.060u 0:00.064
Prokudin-Gorskii.tif[1] TIFF 3702x3205 3702x3205+0+0 16-bit sRGB 134.955MiB 0.000u 0:00.001
Prokudin-Gorskii.tif[2] TIFF 625x175 625x175+841+814 16-bit sRGB 134.955MiB 0.000u 0:00.001

and you can see from the sizes that there are two full layers followed by a reduced size layer that is only annotation or markup on a small area of the image.

Another useful technique is to lay out all the images within a TIFF beside each other in a row across the page, with 10 pixel gaps between, using a command like this:

magick IMAGE.TIFF +smush 10 contents.jpg

enter image description here

We can now see that the three layers in the foregoing image correspond to a flattened version of all the layers on the left, followed by the two individual layers themselves in the centre and the reduced size yellow line overlay layer on the right.

If we then determine that it is only the first, flattened image we are interested in, we can extract and manipulate that alone by adding its sequence number in square brackets afterwards. So, to extract just the first flattened image:

magick IMAGE.TIF[0] extracted.tif

You can also extract multiple individual images and ranges, using commas and dashes.


Note also that magick convert is generally not what you want.

Note also that exiftool is lighter weight than a full ImageMagick installation and can also tell you what's in a multi-IFD TIFF.

Upvotes: 2

Related Questions