Yahoo
Skip to main content
Advertisement
Advertisement
Advertisement
Advertisement

How to Batch Edit Photos in the Linux Terminal

A Linux terminal with Tux holding a paintbrush behind it.
Lucas Gouveia / How-To Geek

ImageMagick is a powerful Linux command line tool for batch editing images. Here's how to use it to crop, resize, and merge photos, as well as remove location information.

First, Install ImageMagick

Batch editing photos in Linux can be done using the ImageMagick program. ImageMagick is a free tool for creating and editing images from the command line, and can resize, crop, convert, rotate, and perform other bulk image actions.

The Linux terminal command examples on this page all use ImageMagick, which you can install on Debian/Ubuntu systems by running:

Or on Fedora Linux by running:

You should check what the terminal commands you copy/paste from the internet do before you run them! While I've explained the ones in this article, commands can have unintended effects on different systems, and people have been known to post harmless-looking commands online that can actually do a lot of damage.

Batch Remove EXIF Data From Images

EXIF data contains information about the device that was used to take a photo, color information, and other data that is useful for photographers. It can also include the location the photo was taken, a privacy concern if you're uploading the image to the internet.

Advertisement
Advertisement

You can remove all the EXIF data from a batch of JPG and PNG images using the following Linux terminal command:

Here's a quick explanation of how this command (and the others on this page) perform bulk editing on multiple image files:

  • A for loop iterates over all the .jpg, .jpeg, and .png(note that file names and extensions are case-sensitive!) in the source directory. Within the loop, the path to each image file is assigned to the $filevariable.

  • The $filevariable is passed to the ImageMagick convert command with the -stripoption that tells it to strip all EXIF data.

  • The final parameter passed to the convert command is the output file path. In this case, the output is saved to a different folder with the same file name, so your original image is left intact.

Batch Resize Photos

The below ImageMagick terminal command resizes all the images in the source directory to 1024x768 pixels using the -resizeoption:

You can specify any resolution here, but keep in mind your image will be stretched if the aspect ratio doesn't match.

Batch Crop Photos

This command batch crops images in a directory to 800x600 pixels:

Note the 800x600+0+0passed to the -cropoption: the 800x600bit is the pixel dimensions you want to crop (the area of the photo you want to keep). The +0+0is the X/Y pixel coordinates of where the crop should start, in this case, starting in the top-left corner.

Batch Watermark Images

Watermarking images is an easy way to protect your creative work when you share it with others. This Linux terminal command adds a watermark to a batch of files:

In this example, the convertcommand uses the -gravityoption in conjunction with the -drawoption to draw the text"My watermark" with a font -pointsizeof 20in the bottom-right (southeast corner) of each image. The 5,5pixel coordinates specify the offset from the southeast corner, adding a 5 pixel margin between the watermark text and the edge of the image.

Convert Image File Formats

This ImageMagick command batch converts JPG images to PNG:

The format of the output image is specified by the file name you give it. The ImageMagick convert command supports the following popular image file formats: JPEG , PNG, GIV, TIFF, BMP, SVG, WEBP , HEIC, and RAW. It can also handle PDF files and SVG vector images.

Rotate Images in Bulk

You can bulk-rotate images using the following command:

Replace the 90degrees specified with the rotation you wish to apply.

Batch Flip (Mirror) Images

Use the flipand flopImageMagick convert options to flip images vertically or horizontally:

Advertisement
Advertisement

To bulk flip, or mirror, images vertically:

To bulk flip images horizontally:

Change JPEG Quality

You can reduce the size of JPG images by reducing their quality:

This command sets the quality of the images to 85using the -qualityoption. Note that when you reduce the quality of an image, that quality can't be restored (even by changing the quality back to a higher value).

JPEG quality is set on a scale of 0-100, with 100 being the maximum quality for archival storage and professional photography, and 60-75 being suitable for online sharing or for use on websites. Anything under 50 will start to look a bit shabby, even at the default zoom level.

Rename Images in Bulk

The cp(copy) command can be used to bulk rename images in Linux:

This example appends the text _renamedto all the images in the source directory.

Auto Crop and Trim

The -trimoption for the convert command automatically crops images based on the background color, determined by the color of the pixels in each of the images' corners:

Merge Images to Create Collages

The montage ImageMagick tool can be used to create collages and merge images:

This command takes all the images in the source directory and creates a 2x2 grid with them with the -tileoption, with a 5 pixel gap specified by the -geometryoption. If there are more than 4 images, additional grids will be created to display them.

Linux Creativity

Linux is becoming increasingly popular with creatives. Not only has its creativity software reached the point where it can be used in professional scenarios , its command line and automation tools can save you time managing and converting your images for publishing and sharing.

Advertisement
Advertisement
Mobilize your Website
View Site in Mobile | Classic
Share by: