- Editing Pictures on Linux Command LineВ with ImageMagick
- Resize an image on LinuxВ command line
- Convert the file type
- Get Information about the particular image
- Flipping an image
- Color list
- Conversion of the colored image into Black and White
- Addition of a border to an image
- Negated image
- Conversion of an image into pdf
- Display
- Conclusion
- Karim Buzdar
- 3 CLI Image Viewers To Display Images In The Terminal
- 1. Display Images In the Terminal Using FIM
- Install FIM
- FIM Usage
- 2. Display Images In the Terminal Using Viu
- Install Viu
- Viu usage
- 3. Display Images In the Terminal Using Lsix
- How to display Images in the command line in Linux/Ubuntu
- Using FIM (FrameBuffer Improved)
- FIM installation
- How to use FIM
- Opening multiple images
- Recursive image display
- FIM Keyboard shortcuts
- Using eog (Eye of Gnome)
- Installing eog
- Displaying images in the terminal
- Using lsix
- Installing lsix
- Start showing thumbnails
- Using feh
- Using Viu
- Viu installation
- How to use Viu tool
- Multiple images display
- Multiple image formats support
- Conclusion
Editing Pictures on Linux Command LineВ with ImageMagick
Every time we deal with images in a command line, we need to install or use any of the command line tools. Few of them include GraphicsMagick, Scrot, Feh, Exiv2 etc. These tools allow us to convert, also help us to resize, compare, animate, and view the images. Each tool has its own usage. In this tutorial, we will learn how to do the basic editing of pictures from Linux command line when needed. We will be using ImageMagick for this purpose which is most commonly used.
Resize an image on LinuxВ command line
In order to resize an image in Linux terminal, you need to follow the following steps.
Step 1: First of all, open Terminal by clicking on Ubuntu launcher and search for Terminal.
Step 2: Now click on the Terminal and wait for the terminal to open.
Step 3: Once the terminal is opened, you will have a screen like this:
Step 4:
Next, once the terminal has been opened, we need to install ImageMagick to proceed further with the resizing, the command used to this purpose is “sudo apt-get install ImageMagick”.
Enter the required credentials to proceed further.
The installation will begin and your screen will be displayed as shown below.
In order to continue the installation further, type Y.
After the final installation, this is the display on the command line.
Now, we want to resize the image. It is currently located at the Desktop with a name index.png
We will move our current directory to the Desktop, where our image is located.
The image we want to resize is index.png so we write a command, with the original name of the image and then we will right the percentage to which we want the resize to happen and then, we will store it in a new file name with .png extension.
Here the new image that is resized by 60% is created named newindex.png
The two images show the different sizes of the same index.png which we have resized using the command.
Convert the file type
Since the above image file was in png and we want to convert into.jpg Now, we will enter the command to do so by using convert command and writing the type of file next to the type we want to convert to.
So, the file has now been converted into another type that is .jpg
Get Information about the particular image
If you want to obtain any sort of information about an image, run simply the command.
All of the information about the image is revealed.
For further details, we simply type this command.
The outcome which we will be getting is.
Flipping an image
If we plan to flip an image in the command line of Linux, it is not a difficult thing to do rather, just write covert –flip imageName.jpg FlippedImageName.png. This will let us achieve the desired outcome.
The new image named Flipped-index on the Desktop can be seen.
This is the flipped image once we opened it. As you can see it is the image we desired to get. Our image has been flipped by 90 degrees as the following figure also shows the same.
This is how we can flip our images using the command line.
Color list
To know all colors used in an image, issue we use a simple command that will help us in knowing the colors that are involved in composing an image.
The output will be a display of a list of colors we have for our index image.
So, this is how we get the color list of any particular image we want.
Conversion of the colored image into Black and White
We can also convert a colored image into black and white by using the Linux Command Line. The command is
Addition of a border to an image
We can also add the border to any image we want to and it could be of any color as in our example we have added the red border. The command used for this is
The border-index is the border added image.
The image once opened, has a border to it which is red in color, the following figure shows the same.
Negated image
We can also negate any image whenever we want to by using the following command:
The negated-index is created on the Desktop.
The negated image is as follows:
Conversion of an image into pdf
Any image can be converted into pdf by using the command.
Where we just write convert imageName*.* FileName.pdf.
A new pdf will be created for that particular image as displayed on the Desktop of our system.
Thus the image has been saved in the pdf versions as shown below:
Display
At last, we will see the command if you want to edit an image on your own using GUI of ImageMagick, run the following command.
So, the GUI will eventually appear, allowing you to make changes.
Conclusion
In this tutorial, we have discussed many interesting ways to edit an image. The most common method used for editing is ImageMagick so in this tutorial, we have also used the same and done its installation first. Then we saw many applications and actions we can perform using ImageMagick. First, we did the resizing of an image, then we learned how to change the file type as per our need, after that we saw how to display the information of an image, then we saw how do we flip an image, then we saw the ways to see colors in an image. Then we saw a technique to convert an image that is colored into black and white, then we added a border (colored) to an image. Later we converted the image into a pdf file. At last, we saw how can we display the GUI so that we can use ImageMagick. These are the basic but necessary commands helpful for a Linux user to learn for editing an image in Linux.
Karim Buzdar
About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn
3 CLI Image Viewers To Display Images In The Terminal
There are plenty of GUI applications available to view images in Linux. But I haven’t used any CLI applications yet which displays pictures in the Terminal itself. To my luck, I found 3 CLI image viewers to display images in Terminal itself. These applications could be useful for those who wants to use CLI alternatives for GUI apps and who live in Terminal mostly.
1. Display Images In the Terminal Using FIM
FIM stands for Fbi IMproved. For those who don’t know, Fbi is a linux framebuffer imageviewer. It uses the system’s framebuffer to display images directly from the command line. By default, it displays bmp, gif, jpeg, PhotoCD, png, ppm, tiff, and xwd from the Terminal itself. For other formats, it will try to use ImageMagick’s convert. The FIM utility draw my attention, because it is very lightweight compared to most GUI picture viewer applications.
FIM is based on Fbi and it is a highly customizable and scriptable image viewer targeted at the users who are comfortable with software like the Vim text editor or the Mutt mail user agent. It displays the images in full screen and the images can be controlled (such as resize, flip, zoom) using keyboard shortcuts. Unlike fbi, the FIM utility is universal. It can open many file formats and it can display pictures in the following video modes:
- Graphically, with the Linux framebuffer device.
- Graphically, under X/Xorg, using the SDL library.
- Graphically, under X/Xorg, using the Imlib2 library.
- Rendered as ASCII Art in any textual console, using the AAlib library.
FIM is completely free and open source.
Install FIM
The FIM image viewer is available in the default repositories of DEB-based systems such as Ubuntu, Linux Mint. So, you can install fbi using command:
If it is not available in the default repositories of your Linux distribution, you can download, compile and install from source as described in the section titled «Download and build instructions» in official documentation page.
FIM Usage
Once installed, you can display an image with «auto zoom» option using command:
Here is the sample output from my Ubuntu box.
Display Images In the Terminal Using Fim
As you can see in the above screenshot, FIM didn’t use any external GUI picture viewers. Instead, it uses our system’s framebuffer to display the image.
If you have multiple .jpg files in the current directory, you could use wildcard to open all of them as shown below.
To open all images in a directory, for example Pictures, run:
We can also open the images recursively in a folder and its sub-folder and then sorting the list like below.
To render the image in ASCII format, you can use -t flag.
To quit Fim, press ESC or q.
Keyboard shortcuts
You can use various keyboard shortcuts to manage the images. For example, to load next image and previous images, press PgUp/PgDown keys. Ton Zoom in or out, use +/- keys. Here is the common keys used to control images in FIM.
- PageUp/Down : Prev/Next image
- +/- : Zoom in/out
- a : Autoscale
- w : Fit to width
- h : Fit to height
- j/k : Pan down/up
- f/m : flip/mirror
- r/R : Rotate (Clock wise and ant-clock wise)
- ESC/q : Quit
For complete details, refer man pages.
2. Display Images In the Terminal Using Viu
Viu is yet another command line application to view images from the Terminal. It is free, open source CLI image viewer written using Rust programming language. Using Viu we can;
- Display popular type of image, including .jpg, .png, igif etc.
- Display images in custom dimensions.
- Display images directly from the image hosting platforms, for example giphy.
Install Viu
Since Viu is written in Rust, we can install it using Cargo package manager. After installing Rust in your Linux box, run the following command to install Viu.
On Arch Linux and its derivatives, It can be installed from AUR using any AUR helper programs like Yay.
Viu is also available as per-compiled binary. Download the latest binary from the releases page. As of writing this, the latest version was 0.2.1.
After downloading the Viu binary file, make it executable:
And, move it to your path, for example /usr/local/bin.
Viu usage
Viu usage is trivial. Just type viu followed by the image path and hit ENTER key.
Display Images In the Terminal Using Viu
You can even display custom dimension image using -h (Height) or -w (Width) flags like below.
Display custom size image using Viu
To display multiple images one after another in a folder, use wildcard characters like below.
Like I already mentioned, Viu is capable of displaying different format images. For example, the following command will display the gif image using Viu:
Display animated images
To exit, just press CTRL+C.
It is also possible to display the image hosting sites, for example Giphy, in Terminal like below.
For more details about Viu, refer the help section by typing the command:
3. Display Images In the Terminal Using Lsix
Unlike the previous two image viewers, Lsix will only display thumbnails in Terminal. It is like ‘ls’ command in Unix-like systems, but for images only. Lsix is a simple BASH script to view thumbnail images in Terminal using Sixel graphics. For more details about this script, please click the following link.
And, that’s all for now. If you use/know any other CLI image viewers, please mention them in the comment section below. I will check and update the guide.
How to display Images in the command line in Linux/Ubuntu
Update d on 5/5/2022 – For users who work with the command line in Linux most of the time, it could be convenient to view images within their terminal session. In this article we will cover some command line applications that enable users to display images in the terminal. Make sure to protect your eyes from your screen’s damaging blue rays while reading the article.
Using FIM (FrameBuffer Improved)
FIM is a utility used to display images or graphics on the Linux terminal. Most beginners never thought it was possible to display images (PNG, JPG, BMP…) on the console. FIM, a scriptable and a highly customizable open source image viewer enables users who spend most of their time working on the terminal. It gives them the possibility to control how images can be zoomed or resized using keyboard shortcuts.
FIM installation
Much like most packages, FIM can be found in Ubuntu default repositories. In order to install it , run the command :
sudo apt-get install fim
In case the package cannot be found in the Ubuntu default repositories, you can always download it so that you can compile it from the source. Refer to this page for guidance.
How to use FIM
Once FIM is installed successfully, you can try to display an image using the command:
Ubuntu image viewer command line
From the obtained snapshot above, one would notice that no known picture viewer was used except FIM which used the system’s framebuffer to show the image.
To quit Fim, simply press ESC or q.
Opening multiple images
To display several images at once in your current folder, you could open them all using wildcards as shown below :
In case your images are located in another directory, simply execute the command below:
Recursive image display
FIM allows also to open images in a recursive manner in a directory as well as its sub-directory as shown by the command below:
fim -R directory_with_images/
FIM Keyboard shortcuts
There are many keyboard shortcuts that help manage the images in the console.
For instance, to zoom in or out, press the +/- keys . To load next or previous images, use the PgUp/PgDown keys. Below are some common shortcuts along with their functionalities:
a : Auto-scale
w : Fit % width
h : Fit % height
PageUp / PageDown : Prev/Next picture
+/- : Zooming in/out
j/k : Panning down/up
f/m : flipping/mirroring
r/R : Rotation (Clock-wise or anti clock-wise)
ESC/q : Exit or Quit
For more details, refer to man pages by running
Using eog (Eye of Gnome)
The Eye of Gnome or eog is the default image viewer in Ubuntu. It is readily available on most recent Ubuntu versions by default. It supports several image extensions and can display single images or multiple images.
Installing eog
As a Gnome application, eog can be found in the Ubuntu Bionic Main repository. As you will see below, It can be easily installed using the usual apt-get command :
sudo apt-get install eog
Displaying images in the terminal
Apart from being a desktop utility, eog is also able to display images on the console directly. Run the command below on your favorite picture:
Open image from terminal
Using lsix
lsix is a tool used to display thumbnail images in the console. lsix, which uses ImageMagick, supports many image formats. lsix , which is written in BASH, intelligently detects the current console background color in order to display the thumbnails clearly.Since lsix uses sixel graphics, it self-detects if the current terminal supports this type of bitmap graphics format (sixel).
Installing lsix
As lsix relies on ImageMagick, would you need to ensure first that it is already installed. It is readily available for instance in the Ubuntu default repositories as well as other Linux distributions.
In order to install it on Ubuntu or Debian, run the command below :
sudo apt-get install imagemagick
As mentioned earlier, lsix is a BASH script and thus no installation is required. You would just need to download it and append it to your $PATH.
To download the latest version of lsix from its official github page, run the command:
Once this has finished, extract the downloaded zip file using the command:
This will extract all the file contents into a directory called lsix-master. All what you need now is to copy the lsix binary file from this folder to your $PATH, as mentioned earlier.
Last but not least, make the lsix binary file executable by running the command :
sudo chmod +x /usr/local/bin/lsix
Assuming you have copied the file into the directory /usr/local/bin/ .
Start showing thumbnails
Since Sixel graphics is not enabled by default and since it is supported by Xterm you would need to start Xterm with Sixel mode using the command below :
Ubuntu open image from terminal
Now to display thumbnails, you only need to invoke lsix command followed by your image as shown below :
To display the thumbnails in your current directory, simply execute:
To display for instance only JPG images, use the command below :
Using feh
Feh is a small light and fast utility used to display and manipulate images. feh , an extremely configurable tool, is mainly intended to be invoked in the console. It allows you to display images stored locally or on the internet (by url). It is used either to display images on the screen or to display wallpaper as a background. Run the command man feh to find out more about the usage of this program.
To run feh, execute it from the terminal prompt by specifying a particular picture:
feh lion.png [feh linux command]
The command will display the image in a frame.
Using Viu
Viu is a command line utility that help view images from within the Terminal. It is open source and free image viewer. Viu allows you to display images with the following formats : png, jpg, igif etc.
Viu installation
As Viu is written in Rust programming language, you should be able to install it via Cargo package manager. Once Rust is installed, execute the command below in order to install Viu :
cargo install viu
Viu can also be acquired as a pre-compiled binary that can be downloaded from the following page. Once the Viu binary file has been downloaded, would you need to make it executable by running the command:
You could afterwards put it in the /bin directory for instance :
sudo mv viu /usr/local/bin/
How to use Viu tool
Much like Fim, Viu is easy to use. Simply type in viu in your terminal followed by the picture full path as follows:
To customize the dimensions of the image , you could use -w (Width) or -h (Height) switches as shown below:
viu your_image.png -w 90
Multiple images display
To display several images in a directory, use a command like the one below :
Multiple image formats support
Viu can also display different types of images. For instance, the command below will display the jpg image:
For more information about Viu, type in the command:
Conclusion
You have three tools that allow you to display images in the terminal. This is handy when you spend most of your time writing commands. lsix is especially useful when it comes to displaying thumbnails though its installation is not as straightforward as the other tools. In case you are on Gnome, you can use eog , or feh as well. If you have imagemagick installed, you can use its display command-line utility. cacaview is yet another lightweight utility that can also be used for the same purpose.
If you know other similar utilities, do not hesitate to mention them in the comments area below.
If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.