Image Converter & Manipulator - Command Line Tools by Hexmos

Convert and manipulate images with command-line tools. Resize, annotate, crop, rotate, add borders, change quality, apply effects, and combine images to PDF.

Image Converter & Manipulator

Command Line Image Conversion and Manipulation

This section provides practical examples of using command-line tools for image conversion and manipulation. These commands are typically executed in a terminal environment and offer powerful capabilities for batch processing and scripting.

Image Resizing Techniques

Resizing images is a common task. The convert command allows for flexible resizing options, including setting a fixed width, a fixed height, or both. It can also change the image format during the resize operation.

# Resize an image to a fixed width and proportional height.
convert original-image.jpg -resize 100x converted-image.jpg

# Resize an image to a fixed height and proportional width.
convert original-image.jpg -resize x100 converted-image.jpg

# Resize an image to a fixed width and height.
convert original-image.jpg -resize 100x100 converted-image.jpg

# Resize an image and simultaneously change its file type.
convert original-image.jpg -resize 100x converted-image.png

# Resize all of the images within a directory, using a for loop.
for file in original/image/path/*; do
    convert "$file" -resize 150 converted/image/path/"$file"
done

Advanced Image Manipulations

Beyond simple resizing, command-line tools enable more complex image editing. This includes adding text annotations, cropping specific sections, rotating images by any angle, and adding decorative borders.

# Make text annotation, which in this example is 'Flower'.
convert flower.jpg -font courier -fill white -pointsize 20 -annotate +50+50 'Flower' flower_annotate1.jpg

# Crop an image.
convert flower.jpg -crop 128×128+50+50 flower_crop.jpg

# Rotate an image.
convert flower.jpg -rotate 45 flower_rotate45.jpg

# Add a border around an image.
convert -border 1x1 -bordercolor "#FFFFFF" image.png new-image.png

Format Conversion and Effects

Easily convert images between different formats, such as PNG to JPEG, while controlling the compression quality. You can also apply various visual effects, like grayscale and vignettes, to batches of images.

# Convert PNG to JPEG, with 70% quality.
convert -quality 70 image.png new_image.jpg

# Apply vignette & grayscale effects to all JPGs in the CWD, using a for loop.
for FILE in *.jpg; do { convert -background black -colorspace gray -vignette 200x100 "$FILE" "$FILE"; } done

Combining Images into a PDF

A powerful feature is the ability to combine multiple image files into a single document, such as a PDF. This is useful for creating reports or presentations from a series of images.

# Convert and combine multiple images to a single PDF.
convert image1.png image2.jpg image3.bmp output.pdf

Further Resources

For more in-depth information on image manipulation with command-line tools, refer to the official documentation: