Adding Text to Images Using Linux Command Line

Post Reply
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#1

Sometimes you want to annotate an image to suit some needs. To add text on images using ImageMagick with the Linux command line, follow steps below.

Before installing any software, it is recommended to update your system to ensure you have the latest package information. Open Terminal and run the an appropriate command depending on your Linux distribution:

Fo Ubuntu Linux:

  1. sudo apt-get update


For RHEL (Red Hat Enterprise Linux), CentOS, and Fedora systems:

  1. sudo dnf update


For Arch Linux:

  1. pacman -Syy


Install ImageMagick if it is not already installed on your system


To confirm that ImageMagick has been installed successfully:

  1. magick -version


Add Text to Image

Open the terminal and navigate to the directory where the image is located. Use the convert command followed by the image filename to apply text:

  1. convert original_image.jpg -gravity location -pointsize fontsize -fill color -annotate +X_offset+Y_offset "text" modified_image.jpg


You can adjust the font, color, and position of your text by modifying the command parameters. For example, you can use a different font by adding the -font parameter:

  1. convert original_image.jpg -gravity location -pointsize fontsize -font Times-Roman -fill color -annotate +X_offset+Y_offset "text" modified_image.jpg

Where
  • original_image.jpg: Replace it with the actual image filename.
  • gravity location: Specifies the position to anchor the text (e.g., NorthWest, Center, South).
  • fill: Specifies the color of the text.
  • annotate: is the position of the text.
  • pointsize fontsize: Determines the size of the text.
  • +X_offset+Y_offset: Sets the X and Y offsets in pixels. It indicates the X and Y coordinates of the text relative to the top left corner of the image.
  • "text": Replace it with the desired text.
  • modified_image.jpg: Replace it with the desired output image filename.
As an example, execute the following command and the modified image with the added text will be saved in the current directory:

  1. convert original_image.png -gravity SouthEast -pointsize 36 -font Times-Roman -fill darkblue -annotate +50+50 "www.tssfl.com" photo_with_text.jpg


Note: You can experiment with different options to achieve the desired look and feel for the added text.

See attached example of the original and the annotated images.
Attachments
output.png
(20.32 KiB) Not downloaded yet
output.png
(20.32 KiB) Not downloaded yet
TSSFL_Stack.png
(16.98 KiB) Not downloaded yet
TSSFL_Stack.png
(16.98 KiB) Not downloaded yet
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
Post Reply
  • Similar Topics
    Replies
    Views
    Last post

Return to “Linux and Unix Based Operating Systems”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 5 guests