Hackers Choice
Home
Videos

How to Compress and Resize Images from Thunar File Manager in Linux

How to Compress and Resize Images from Thunar File Manager in Linux

By Yashdeep Raj •  2019-10-10T11:49:52.018Z •  Unix & Linux

68 views

If you find you’re recompressing and resizing images day-in, day-out, for example, for use with a specific resolution on your blog’s pages, why not turn the procedure into a one-click affair? You can do it by exploiting Thunar’s support for external functions.

We should note that you can do the same thing with any other “programmable” file managers, like Konqueror.

Install Thunar and ImageMagick

Use your favorite software/package management solution to find and install Thunar and ImageMagick if they aren’t already installed in your distribution. For Debian-based distributions you could do it with:

sudo apt-get install thunar imagemagick

Since most distributions come with some GUI application that gives access to everything in their repositories, usually presented as an “App Store,” searching through it for the programs and clicking on an “Install” button is probably the better option for people who hate the terminal.

Thunar With Imagemagick 001

Visit ImageMagick’s Option Summary page

Although we will only talk about scaling down and saving any selected image file as a compressed JPG, ImageMagick offers dozens of other options for altering your image files. Visit its official Options Summary page to check out everything it can do. Using those options, you can expand on what we’ll build together, either creating a more sophisticated version of our command or different commands that manipulate your images in different ways.

Thunar With Imagemagick 002

Create a test folder and copy some pictures there

Never act on your original files – one wrong move, and they’ll be altered or, worse, gone forever. Create a test folder somewhere – like in your Pictures folder – and copy some files there we’ll use as … well… guinea pigs! When there, right-click on the empty space of Thunar’s file list display and select terminal from the menu.

Thunar With Imagemagick 003

Find the optimal compression/quality ratio

The next step is to find the best compression/quality ratio for you. Each of us is different, so what looks good for us might seem too low-quality for you. It also depends on the content of your images: the kittens in our test images, and photos in general, can take larger compression/lower quality settings than sharper illustrations. Those, in turn, can be compressed more than screenshots where text must remain legible.

Do some test runs until you find the optimal value for you, using the command:

magick INPUT_FILE -quality QQ OUTPUT_FILE

Where INPUT_FILE is your original image, OUTPUT_FILE the compressed and converted result, and QQ a number from 1 to 100 – the higher the number, the better the quality and lesser the compression.

Thunar With Imagemagick 004

Resizing or scaling down your images

Resizing and scaling down are different, as with resizing you can also scale up. ImageMagick allows you to resize your images by using the command:

magick INPUT_FILE -resize 1920x1200 OUTPUT_FILE

Here we used the 1920 x 1200 resolution. If it sounds strange, it’s because we’re using a monitor with 16:10 instead of 16:9 ratio, which would come with a more typical 1920 x 1080 resolution. Whatever number you choose, ImageMagick, by default, will keep your image file’s proportions and scale it only in one dimension to avoid distorting it. However, this will also “scale up” any smaller images, and we wouldn’t want that since our goal is to reduce our images’ sizes for online use. You can tell ImageMagick to only resize images if their larger than the selected resolution. Just add > after the entered resolution to do so.

magick INPUT_FILE -resize 1920x1200> OUTPUT_FILE

Thunar With Imagemagick 005

Add the command to Thunar

When you’ve found the desired compression/quality ratio and set your target resolution to downscale, copy the command from your terminal to the clipboard. Then, from Thunar, select “Edit > Configure custom actions …”

Enter a name for your action and, if you want, a description. Then, paste the copied ImageMagick command into the Command field.

Select the input filename in the command and change it to “%f,” then select the output filename and change it to “%f_output.”

The command won’t work if you don’t set a condition for its appearance. Move to the Appearance Conditions tab and select “Image Files” so that our command will appear whenever any image files are selected. Click OK and your custom action will be saved for future use.

Thunar With Imagemagick 006

Try your custom action

The custom action will appear whenever you right-click on an image file. By selecting it, a new, compressed and scaled-down file will appear in the same folder with “_output” after its name. Unfortunately, Thunar isn’t versatile enough to only parse the “basename” to ImageMagick (“to remove the extension”), so we have to do it manually. There are ways to avoid that, but we’d have to create more complex scripts.

Thunar With Imagemagick 007

However, that’s a story for another time. Until then, why not create some more alternative takes on your command, with different compression levels or resolution targets for your every need? They’ll only be a right-click away!

Yashdeep Raj
Author
 You may also like
Download our apps
Get it on Google Play