Quick Links
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 theImageMagickprogram. 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 datacontains 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.
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:
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 the800x600+0+0passed to the-cropoption: the800x600bit 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, theconvertcommand uses the-gravityoption in conjunction with the-drawoption to draw thetext"My watermark" with a font-pointsizeof20in the bottom-right (southeast corner) of each image. The5,5pixel coordinates specify the offset from the southeast corner, adding a 5 pixel margin between the watermark text and the edge of the image.
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.
Use theflipandflopImageMagick convert options to flip images vertically or horizontally:
To bulk flip, or mirror, images vertically:
Change JPEG Quality
You can reduce the size of JPG images by reducing their quality:
This command sets the quality of the images to85using 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
Thecp(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
ThemontageImageMagick 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 inprofessional scenarios, itscommand line and automation toolscan save you time managing and converting your images for publishing and sharing.