Lyk Lyk - 3 months ago 19
Linux Question

How to convert a large series of .img files to a gif with image magick (IM) from command line

I have a set of 1800 images (16Mb each, of the .img type).

I would like to convert them into a gif from the command line as I am remotely connected to the server they are stored on and it is not feasible to download all of them (for use with local programs). I cannot install new programs on the server, but it has imagemagick installed (IM).

When I try the standard command:

convert -resize 20% -delay 5 -loop 0 /pwd/*.img output.gif

I get an error of
no decode delegate for this image format IMG @ error/constitute.c/ReadImage/504.

convert: no images defined d263g_07.gif @ error/convert.c/ConvertImageCommand/3257.

Is there a way to handle img formats at all in IM? It seems in their documentation it is not a supported filetype, but other googling says .img images are very near bitmaps in format. I wonder if there is a piping option or something that would let me accomplish my goal?

EDIT: These are images straight from a CMOS detector of diffraction patterns (x-ray crystallography).
Also I just found a hidden imageJ executable as well. So if that offers options not available to IM, that could be a solution as well.


As a first attempt, I think you will need something along these lines:


for f in *img; do
    cat "$f" | convert -depth 16 -size 2952x2820+3072 gray:- -resize 800x -normalize -depth 8 MIFF:-
done | convert - -delay 80 result.gif

You may need to decrease the quality, or sub-sample frames or further reduce the size to get an acceptable GIF size. To decrease the size, change it to -resize 500x maybe. Or to reduce the quality (and therefore the size), add in -quality 75% or similar. See how you get on and report back!

So, save the above in a file called go in your HOME (login) directory, then execute the following command (just once) to make it executable:

chmod +x $HOME/go

Then, go to the directory where the images are stored, e.g.:

cd /some/place/images

and run the script by typing:


After a while it will hopefully finish and the animated GIF will be called result.gif. If you still have problems, copy each line below as is and then paste them, one line at a time into your Terminal:

for f in *img; do cat "$f" | 
convert -depth 16 -size 2952x2820+3072 gray:- -resize 800x -normalize -depth 8 MIFF:- done |
convert - -delay 80 result.gif

I don't know what viewers you have installed, but you could try:

feh results.gif

Original Answer

I think we may have to do this answer stepwise... does this look like your image:

enter image description here

I got it like this:

convert -depth 16 -size 2952x2820+3072 gray:- -normalize a.jpg < ~/Desktop/d263g-07_1_0001.img