Created
July 2, 2024 21:39
-
-
Save banagale/1e4cb1840f5059f6b868190bdb017781 to your computer and use it in GitHub Desktop.
Convert and Resize images to something more reasonable for email
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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