Skip to content

Instantly share code, notes, and snippets.

@tachoknight
Created August 22, 2025 14:05
Show Gist options
  • Select an option

  • Save tachoknight/a05575a3c013f40f2864a2d8d3295061 to your computer and use it in GitHub Desktop.

Select an option

Save tachoknight/a05575a3c013f40f2864a2d8d3295061 to your computer and use it in GitHub Desktop.
Example of script that uses ImageMagick to strip the EXIF data from an image
#!/bin/zsh
# This script requires a filename to be passed in.
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <image-file>"
exit 1
fi
if [ ! -f "$1" ]; then
echo "Error: File '$1' does not exist or is not a regular file."
exit 1
fi
# Check if the file is an image by checking its MIME type
MIME_TYPE=$(file --mime-type -b "$1")
if [[ ! "$MIME_TYPE" =~ ^image/ ]]; then
echo "Error: '$1' is not a valid image file."
exit 1
fi
# Use ImageMagick to strip EXIF data while preserving the ICC profile
magick $1 $1.icm
magick $1 -strip -profile $1.icm $1_stripped
# Remove the original file and rename the new file
mv -f "$1_stripped" "$1"
# and remove the icc profile file
rm $1.icm
# Print success message
echo "Successfully stripped EXIF data from '$1'."
# Exit with success status
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment