image compression script with aesthetic filter and non aesthetic filter
This commit is contained in:
parent
73cacf0f1a
commit
7ba49face9
34
compress_img_aesthetic.sh
Normal file
34
compress_img_aesthetic.sh
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Prompt for input and output directories
|
||||||
|
read -p "Enter the input directory containing images: " INPUT_DIR
|
||||||
|
read -p "Enter the output directory for compressed images: " OUTPUT_DIR
|
||||||
|
|
||||||
|
# Check if input directory exists
|
||||||
|
if [ ! -d "$INPUT_DIR" ]; then
|
||||||
|
echo "Input directory does not exist. Please provide a valid directory."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create output directory if it doesn't exist
|
||||||
|
mkdir -p "$OUTPUT_DIR"
|
||||||
|
|
||||||
|
# Loop through all images in the input directory
|
||||||
|
for img in "$INPUT_DIR"/*.{jpg,jpeg,png}; do
|
||||||
|
[ -e "$img" ] || continue
|
||||||
|
|
||||||
|
# Get filename without extension
|
||||||
|
filename=$(basename "$img")
|
||||||
|
output="${OUTPUT_DIR}/${filename%.*}.jpg"
|
||||||
|
|
||||||
|
# Compress and style image without reducing brightness
|
||||||
|
ffmpeg -i "$img" \
|
||||||
|
-vf "scale=iw*0.8:ih*0.8,eq=contrast=1.1:saturation=0.8,noise=alls=15:allf=t+u" \
|
||||||
|
-q:v 3 \
|
||||||
|
"$output"
|
||||||
|
|
||||||
|
echo "Processed $img -> $output"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "All images processed and saved in $OUTPUT_DIR"
|
||||||
|
|
34
compress_img_no_aesthetic.sh
Normal file
34
compress_img_no_aesthetic.sh
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Prompt for input and output directories
|
||||||
|
read -p "Enter the input directory containing images: " INPUT_DIR
|
||||||
|
read -p "Enter the output directory for compressed images: " OUTPUT_DIR
|
||||||
|
|
||||||
|
# Check if input directory exists
|
||||||
|
if [ ! -d "$INPUT_DIR" ]; then
|
||||||
|
echo "Input directory does not exist. Please provide a valid directory."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create output directory if it doesn't exist
|
||||||
|
mkdir -p "$OUTPUT_DIR"
|
||||||
|
|
||||||
|
# Loop through all images in the input directory
|
||||||
|
for img in "$INPUT_DIR"/*.{jpg,jpeg,png}; do
|
||||||
|
[ -e "$img" ] || continue
|
||||||
|
|
||||||
|
# Get filename without extension
|
||||||
|
filename=$(basename "$img")
|
||||||
|
output="${OUTPUT_DIR}/${filename%.*}.jpg"
|
||||||
|
|
||||||
|
# Compress image while maintaining quality
|
||||||
|
ffmpeg -i "$img" \
|
||||||
|
-vf "scale=iw*0.9:ih*0.9" \
|
||||||
|
-q:v 2 \
|
||||||
|
"$output"
|
||||||
|
|
||||||
|
echo "Compressed $img -> $output"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "All images compressed and saved in $OUTPUT_DIR"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user