Linux Command Line Image Manipulation

Resize JPG Images

Describe the characteristics of image files (like resolution) with identify command that is part of ImageMagick and GraphicsMagick (gm identify) suite of tools.

Resizing with gm convert:

gm convert -size 300x400 -resize 300x400 +profile "*" <INPUT> <OUTPUT>

for file in *.jpg; do gm convert -size 150x200 -resize 150x200 +profile "*" ${file} small-${file}; done

Resizing with ffmpeg:

# width = 600, height calculate to retain aspect ratio
ffmpeg -i <INPUT> -vf scale=600:-1 <OUTPUT>

for file in *.jpg; do ffmpeg -i ${file} -vf scale=600:-1 small-${file}; done

Convert Video Formats

# from flv to mp4
for file in *.flv; do ffmpeg -nostdin -hide_banner -loglevel error -i ${file} -vcodec libx265 -acodec copy ${file%.flv}.mp4; done

# from avi to mp4
for file in *.avi; do ffmpeg -nostdin -hide_banner -loglevel error -i ${file} -vcodec libx265 -acodec aac ${file%.avi}.mp4; done

# from mov to mp4
for file in *.mov; do ffmpeg -nostdin -hide_banner -loglevel error -i ${file} -vcodec copy -acodec copy ${file%.mov}.mp4; done

Page Metadata

Source: imaging.md Created: 2025-01-05T20:28:33+02:00 Changed: 2025-07-05T19:38:48+03:00