The ability to sort images by their resolution in dpi

Hello everyone!
I need to sort images by their dpi (72x72, 100x100, 300x300).
In Windows Explorer I just add a new column (resolution horizontal and vertical) and the problem is solved.
I haven’t found yet a Linux file manager or image viewing application that lets me do the same.
The question is as follows: Is it possible to sort many images by their resolution in DPI in Linux (in Manjaro in particular)?

Yes, it is possible.

Thank you for the reply, but, please, enlighten me, HOW? What shall I use or do to sort images by their dpi?

Thanks for asking.

However, these links will probably be more beneficial, initially.

There are likely many ways via command-line to sort files in a variety of ways. However, you haven’t indicated whether that’s something you might be open to; or whether it absolutely has to be done with the GUI.

Some context will be welcomed by forum members. Thanks.

I need to work fast and to sort many hundreds of images regularly. And I shall send images with absolutely identical dpi to a destination. I used to use GUI because I can check images by sight. It’s like looking at a dashboard with all the indexes looking to the right direction. You can immediately sort out a wrong one. It’s a batch control visual procedure. Something like that.

The problem you face is that image dimensions are typically stored within the metadata of the files; and this metadata must be scanned and queried to return these dimensions in a usable format. This could be done for example with:

find -iname '*.jpg' -exec identify -format "%[fx:w*h] %i\n" {} \+ | sort -g

…which uses the identify command available in ImageMagick; which would need to be installed to make it work.

sudo pacman -S imagemagick

That would require you to do some reading, and of course it uses the command-line.

File Managers on the GUI end of the spectrum can scrape useful information aswell, but it generally tends to be for display purposes rather than anything more intensive. That said, I haven’t used all flavours available.

‘DigiKam’ boasts sorting photos files by size. Whether that might extend to dimensions aswell, I don’t know, but you could install it to test the theory.

Thank you very much. I don’t need dimensions, just dpi. And still… to add one more column to a file manager and immediately seeing what you need to see is a bit more productive and practical than using a command line. So, the function is PRACTICALLY absent in Linux.

1 Like

Not strictly true. I simply don’t know which file managers specifically might have advanced file sorting – I usually set and forget, with respect most filetypes.

Someone else may have something to add though, so try not to just abandon the idea because it seems too hard. After all, if it’s going to save you time later, it’s probably well worth making the effort now.

Well you could adapt it to rename them with a prefix containing the dpi, then any file manager should be able to sort them by dpi. Not sure if the order (or the renaming) would be acceptable though.

Or you could sort the files, put them in directories named by dpi.

Or select a particular dpi and copy the files to a temporary directory.

Dolphin has other optional columns to sort by, and data for some of those must have been obtained in a similar fashion; only there’s no obvious exposure allowing additional options such as DPI; unlike the context API, that allows extra actions via downloaded plugins.

Both @ben75 and @scotty65 posted scripts recently (for random renaming) which could probably be adapted for that purpose.

This will loop through a folder & add the DPI to the start of the image files’ names (although not all image files have embedded DPI values - PNG files can have their values in meters, and some also use different field names such as “Pixels Per Unit X”, “Pixels Per Unit Y” & “Pixel Units” to store their DPI values). You haven’t mentioned the image types you want to sort, but this script would work best on a folder of jpegs.

Make sure you are in the directory you want to process before you run the script! The only thing it requires is ImageMagick, which should already be installed on your system.


# dpirename - a script to add the DPI value to the start of image files

# Set extglob which allows the use of "!" to exclude already renamed files from processing

shopt -s extglob

read -p "Image files in $PWD will be renamed with DPI. Do you want to proceed? " -n 1 -r
echo    # (optional) move to a new line

if [[ $REPLY =~ ^[Yy]$ ]]; then

# only loop over files with extensions starting with "j" or "p" that have not already had the DPI added to their file name

for f in !(dpi_*.[jJ][pP]); do

# get the DPI of the main, not embedded thumbnail, image by finding the first instance of "Resolution:" & remove space at start of result

dpi=$(identify -units PixelsPerInch -verbose "${f}" | grep -m 1 Resolution: | cut -d: -f2 | sed -e 's/^[ \t]*//')

# move the file unless the new name already exists (noclobber)
# For non-verbose processing change "-vn" to just "-n"

mv -vn "${f}" "dpi_${dpi}_${f}";



echo "Script is exiting"


# Unset extglob

shopt -u extglob

exit 0

Edit: added directory to be processed confirmation to script

1 Like

Thank you all very much for the help and support. I will try to use scripts, but first of all I will try to maybe find a plugin for Dolphin. If not, it would be good if Manjaro developers think over the possibility to add more features to the file manager to sort images by their parameters. DPI is an important parameter for any photo lab or typography.

The proper place for such requests is not Manjaro but KDE/Plasma

1 Like

You can do it using XnView MP, simply change the view from “Thumbnails” to “Details” and move “DPI” column closer to “Name” column, then click on it to sort your images in ascending or descending order.

@Alex24 – Scroll up.

That seems to fill the order.

Related:- I did some research on exif – from the perspective of potentially adding dpi as a sort option in file managers that allow manipulation of options.

I found that to calculate the dpi, the resolution first needed to be calculated; presumably to have known dimensions to sample from. Finding a suitable file manager, however, quickly became tedious.

Thank you for the real help and support! You made me feel not abandoned! ) I will study all the possibilities. It is all about the pain of moving from Windows to Linux.

You’re welcome, indeed. @medmedin suggested using XnView MP – I think that should solve it for you. I used the Windows version long ago, but didn’t recall a Linux version; and especially not being so readily available. It does what you need with no additional complication. Cheers.

WOW! THANK YOU! I tested your script and it works brilliantly! Generally, I need to check a batch of jpeg images for the correct dpi. Your script lets me do it easily, and I can immediately see any file with wrong dpi that shall be corrected. I take my hat off! Really! )))
I have an additional and indelicate question (forgive me, please). Is it possible to add file size in pixels to the name like, for example, follows:
dpi_100x100_size_3000x2000_rosegarden.jpg (size is horizontal and vertical dimensions in pixels).
It will let me check up the whole batch of images and easily correct errors of processing, if any.
THANK YOU once again!

1 Like

XnView is OK, but the script made by scotty65 is just fantastic. )))

Yes. That works too; albeit not built into a file manager, as I think was the original query. Glad you have a solution, nonetheless. Cheers.