I have about 30 images (all images of the same size: 300x75) in a directory and would like to present them on a grid of size 5x6.

so far I have done it manually:

$ feh -i --thumb-width 300 --thumb-height 75  --limit-width 300*5 --limit-height 75*6 . &

Is there a builtin option to do it? something like this:

$ feh -i --num-rows 5 --num-columns 6 .

Which looks much cleaner, moreover I'd like to avoid:

  1. Stating the original images size thumb-width and thumb-height so in index mode it would not resize the original size.
  2. Calculating manually limit-width and limit-height so all images will get presented.
  • What would you expect from a builtin option to do what exactly? You're showing the switches that you're able to use to do what you want? – slm Aug 4 '18 at 2:17
  • 1
    indeed I was able to this BUT, I'm doing the area calculation manually after figuring out the actual images size with feh --list, I'd like to avoid it (I have updated and elaborated more in the question) Thank you – JammingThebBits Aug 4 '18 at 7:31
  • I would suggest using the montage program instead. e.g. montage <list of images> -tile MxNx0x0 out.jpg – eqzx Feb 13 at 20:37

In researching this I saw nothing that would appear to allow for this natively within feh. The montage switch is the closest but it doesn't allow for any dynamic sizing, merely just displays a montage based on the -H and -W switches.

Given this I feel the best approach would be something like this:

$ cat fehm.bash


 W=$(identify -ping -format '%w' $file)
 H=$(identify -ping -format '%h' $file)
 LW=$(($W * $gridW))
 LH=$(($H * ($gridH + 1)))
 feh -i --index-info '' --thumb-width $W --thumb-height $H \
   --limit-width $LW --limit-height $LH .

 #    --index-info format
 #             Show image information based on format below thumbnails in 
 #             index / thumbnail mode.  See FORMAT SPECIFIERS.  May contain 
 #             newlines. Use "--index-info ''" to display thumbnails without  
 #             any info text
 #             Note: If you specify image-related formats (such as %w or 
 #             %s), feh needs to load all images to calculate the dimensions 
 #             of its own window.  So when using them with many files, it 
 #             will take a while before a feh window becomes visible. Use 
 #             --preload to get a progress bar.
 #   -i, --index
 #             Enable Index mode.  Index mode is similar to montage mode, 
 #             and accepts the same options.  It creates an index print of 
 #             thumbnails, printing the image name beneath each thumbnail.  
 #             Index mode enables certain other options, see INDEX AND 
 #   -H, --limit-height pixels
 #             Limit the height of the montage.
 #   -W, --limit-width pixels
 #             Limit the width of the montage, defaults to 800 pixels.
 #             If both --limit-width and --limit-height are specified, the 
 #             montage will be exactly width x height pixels in dimensions.
 #   -E, --thumb-height pixels
 #             Set thumbnail height.
 #   -y, --thumb-width pixels
 #             Set thumbnail width.

The above could be incorporated into a Bash function instead if you don't want to have to have a script:

$ cat fehm_func.bash
fehm () {

 W=$(identify -ping -format '%w' $file)
 H=$(identify -ping -format '%h' $file)
 LW=$(($W * $gridW))
 LH=$(($H * ($gridH + 1)))
 feh -i --index-info '' --thumb-width $W --thumb-height $H \
   --limit-width $LW --limit-height $LH .

You simply source the above like this:

$ . fehm_func.bash
$ fehm


One thing I noticed while doing this was that your original example didn't appear to work. The setting of the grid to 5x6 would result in only a 5x5. This appears to be due to the space in between the rows of images. To work around this I padded the $gridH calculation by adding a 1 to it, effectively making it 5x7.

 LH=$(($H * ($gridH + 1)))

Example run

With the above in place. I used the following script to construct some sample data. The data is comprised of images identical to your size, 300x75 and they alternative between blue and red, to help in seeing the effects of the solution I'm providing.

$ for i in {01..30};do int=$(expr $i); [ $((int%2)) -eq 0 ] && c=blue || \
   c=red; convert -size 300x75 xc:${c} img${i}.jpg;done

Results in this set of files:

$ ls | column -c 80
img01.jpg   img07.jpg   img13.jpg   img19.jpg   img25.jpg
img02.jpg   img08.jpg   img14.jpg   img20.jpg   img26.jpg
img03.jpg   img09.jpg   img15.jpg   img21.jpg   img27.jpg
img04.jpg   img10.jpg   img16.jpg   img22.jpg   img28.jpg
img05.jpg   img11.jpg   img17.jpg   img23.jpg   img29.jpg
img06.jpg   img12.jpg   img18.jpg   img24.jpg   img30.jpg

With the above data, now if we use our fehm function:

$ fehm



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.