resize images command line

If you have been following us, you might have seen our article on how to add resize option in the right-click context menu in the File manager in Ubuntu. Today, let’s talk about how to resize images by command line via Terminal. Command line way of doing things have their own advantages. In most of the cases, it is highly efficient to use command line when doing things from a remote computer. Also, Terminal consumes the least amount of system resources and is lightning fast.

Resizing images from the Terminal in Ubuntu

To resize images from the terminal, we will be using a free command line utility called imgp. This amazing utility supports batch processing of images and uses the intelligent adaptive algorithm.

Features of imgp

Though the name of the utility could have been better, the features aren’t compromised.  imgp is a good replacement of the Nautilus Image Converter extension because it is not tied to any file manager and so way faster in conversion.

Let’s take a look at its powerful features.

  • supports JPEG and PNG image formats
  • can resize by percentage or resolution
  • supports batch processing of images
  • preserves/ erase EXIF data
  • can rotate images clockwise by the specified angle
  • optimize images
  • specify output JPEG quality
  • completion scripts for bash, fish, zsh

Installation of imgp in Ubuntu, Linux Mint, and elementary OS

The easiest way to install imgp is to via PPA.

Step 1) Launch Terminal.

Step 2) imgp needs Python 3.5 or later, which is installed by default in recent versions of Ubuntu, but in any case, there is no harm in entering this command:

sudo apt-get install python3-pil

Step 3) Use the following command to add PPA.

sudo add-apt-repository ppa:twodopeshaggy/jarun

Step 4) Update:

sudo apt update

Step 5) Install imgp

sudo apt install imgp

That’s it! You can now use the command line to start resizing your images.

READ  How to create App Folders in Ubuntu 17.10

How to use imgp

Convert some images and directories:

imgp -x 1366x768 ~/ ~/Pictures/image3.png ~/Downloads/
/home/testuser/image1.png
3840x2160 -> 1365x768
11104999 bytes -> 1486426 bytes

/home/testuser/image2.jpg
2048x1365 -> 1152x768
224642 bytes -> 31421 bytes

/home/testuser/Pictures/image3.png
1920x1080 -> 1365x768
2811155 bytes -> 1657474 bytes

/home/testuser/Downloads/image4
2048x1365 -> 1152x768
224642 bytes -> 31421 bytes

Scale an image by 75% and overwrite the source image:

imgp -x 75 -w ~/image.jpg
/home/testuser/image.jpg
1366x767 -> 1025x575
120968 bytes -> 45040 bytes

Rotate an image clockwise by 90 degrees:

imgp -o 90 ~/image.jpg
120968 bytes -> 72038 bytes

Adapt the images in the current directory to 1366×1000 resolution.

Visit all directories recursively, overwrite source images, ignore images with matching hres or vres but convert PNG images to JPEG.

imgp -x 1366x1000 -wrack
Set hres=800 and adapt vres maintaining the ratio.

imgp -x 800x0
Source omitted. Processing current directory...

./image1.jpg
1366x911 -> 800x534
69022 bytes -> 35123 bytes

./image2.jpg
1050x1400 -> 800x1067
458092 bytes -> 78089 bytes

Process images greater than 50KB (50*1024 bytes) only:

imgp -wrackx 1366x1000 -s 51200

 

Previous article10 Best New Features of GNOME 3.28
Next articleHow to refresh desktop in Ubuntu without rebooting PC
Hi there! I'm Kiran Kumar, founder of FOSSLinux.com. I'm an avid Linux lover and enjoy hands-on with new promising distros. Currently, I'm using Ubuntu as a daily driver and run several other distros such as Fedora, Solus, Manjaro, Debian, and some new ones on my test PC and virtual machines. I have a day job as an Engineer, and this website is one of my favorite past time activities especially during Winter ;). When I'm not writing for FOSSLinux, I'm seen biking and hiking on scenic trails. Hope you enjoy using this website as much as I do writing for it. Feedback from readers is something that inspires me to do more, and spread Linux love!. If you find a time, drop me an email or feedback from the 'Contact' page. Or simply leave a comment below if you found this article useful. Have a good day!

Leave a Reply

avatar
  Subscribe  
Notify of