All posts
Crop image via CLI
ffmpeg: crop a still image to width×height at x,y.
Open online converterPackages to install
Only ffmpeg is required. JPEG, PNG, WebP, and GIF all work with the same crop filter.
ffmpeg
sudo apt-get update
sudo apt-get install -y ffmpegHow to run the command
Use -vf crop=width:height:x:y. For stills, add -frames:v 1 -update 1 so ffmpeg writes a single image. JPEG quality is -q:v 2.
ffmpeg -y -i photo.jpg -vf crop=640:640:80:40 -frames:v 1 -update 1 -q:v 2 photo.crop.jpgDockerfile example
Build a minimal Ubuntu image with the required packages and run the conversion inside the container.
FROM ubuntu:24.04
RUN apt-get update && \
apt-get install -y --no-install-recommends \
ffmpeg && \
rm -rf /var/lib/apt/lists/*
WORKDIR /work
docker build -t crop-image .
docker run --rm -v "$PWD:/work" -w /work crop-image \
ffmpeg -y -i photo.jpg -vf crop=640:640:80:40 -frames:v 1 -update 1 -q:v 2 photo.crop.jpgExample commands
Run these locally after installing the packages, or inside the container from the Dockerfile.
ffmpeg -y -i photo.jpg -vf crop=640:640:80:40 -frames:v 1 -update 1 -q:v 2 photo.crop.jpgffmpeg -y -i photo.png -vf crop=1080:1920:0:0 -frames:v 1 -update 1 photo.crop.png