Skip to content

Instantly share code, notes, and snippets.

@banagale
Created July 2, 2024 21:39
Show Gist options
  • Save banagale/1e4cb1840f5059f6b868190bdb017781 to your computer and use it in GitHub Desktop.
Save banagale/1e4cb1840f5059f6b868190bdb017781 to your computer and use it in GitHub Desktop.
Convert and Resize images to something more reasonable for email
#!/bin/bash
# Define source and destination directories
SOURCE_DIR="./"
DEST_DIR="./"
# Create destination directory if it doesn't exist
mkdir -p "$DEST_DIR"
# Resize and convert images
for img in "$SOURCE_DIR"*.png; do
# Resize image
sips --resampleWidth 1600 "$img" --out "$DEST_DIR"
# Convert resized image to JPG with more compression
sips -s format jpeg "$DEST_DIR/$(basename "$img")" --setProperty formatOptions 50 --out "$DEST_DIR/$(basename "${img%.png}.jpg")"
# Remove the intermediate PNG file
rm "$DEST_DIR/$(basename "$img")"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment