This script automatically rotates DJI drone images so that North is at the top, based on the Gimbal Yaw Degree stored in the image metadata.
- Extracts Gimbal Yaw Degree (the camera's direction when the photo was taken).
- Computes the correct rotation using the formula:
Rotation Angle = 180 - Gimbal Yaw Degree
- Rotates the image accordingly so that North is correctly up.
⠀Requirements Ensure you have the following installed: ExifTool (for extracting metadata)
brew install exiftool
# macOS
sudo apt install libimage-exiftool-perl
# Linux
ImageMagick (for rotating images)
brew install imagemagick
# macOS
sudo apt install imagemagick
# Linux
exiftool -GimbalYawDegree -s3 "input.jpg"
ROTATION_ANGLE=$(exiftool -GimbalYawDegree -s3 "input.jpg" | awk '{print 180 - $1}')
convert "input.jpg" -rotate "$ROTATION_ANGLE" "output_NorthUp.jpg"
for img in DJI_*.jpg; do
ROTATION_ANGLE=$(exiftool -GimbalYawDegree -s3 "$img" | awk '{print 180 - $1}')
convert "$img" -rotate "$ROTATION_ANGLE" "${img%.*}_NorthUp.jpg"
echo "Processed: $img → ${img%.*}_NorthUp.jpg"
done
- Works for DJI drone images that contain Gimbal Yaw Degree metadata.
- If GimbalYawDegree is missing, the script will not rotate the image.
- The script assumes no extreme camera tilt; it only corrects rotation based on yaw.
Before correction:
- Gimbal Yaw Degree: -65.3° (Camera was pointing ~WNW)
⠀After correction:
- Image rotated 65.3° counterclockwise to align North at the top.