Home Terminal Tuts How to Resize Images by Command line in Ubuntu

How to Resize Images by Command line in Ubuntu

by Kiran Kumar
Published: Updated:
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.

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

 

You may also like

Leave a Comment

fl_logo_v3_footer

ENHANCE YOUR LINUX EXPERIENCE.



FOSS Linux is a leading resource for Linux enthusiasts and professionals alike. With a focus on providing the best Linux tutorials, open-source apps, news, and reviews written by team of expert authors. FOSS Linux is the go-to source for all things Linux.

Whether you’re a beginner or an experienced user, FOSS Linux has something for everyone.

Follow Us

Subscribe

©2016-2023 FOSS LINUX

A PART OF VIBRANT LEAF MEDIA COMPANY.

ALL RIGHTS RESERVED.

“Linux” is the registered trademark by Linus Torvalds in the U.S. and other countries.