optimize char
This commit is contained in:
parent
7771fd71cf
commit
5932b9d7d3
110
.local/bin/optimizechar
Executable file
110
.local/bin/optimizechar
Executable file
@ -0,0 +1,110 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Function to downscale images if they're larger than 960x544
|
||||
downscale_image() {
|
||||
local img="$1"
|
||||
local width height
|
||||
# Get the image dimensions
|
||||
dimensions=$(identify -format "%wx%h" "$img")
|
||||
width=$(echo $dimensions | cut -d'x' -f1)
|
||||
height=$(echo $dimensions | cut -d'x' -f2)
|
||||
|
||||
# If width > 960 or height > 544, resize
|
||||
if [ "$width" -gt 960 ] || [ "$height" -gt 544 ]; then
|
||||
mogrify -resize 960x544\> "$img"
|
||||
echo "Downscaled $img to 960x544"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to resize char_icon to 60x60 if it's bigger
|
||||
resize_char_icon() {
|
||||
local img="$1"
|
||||
local width height
|
||||
# Get the image dimensions
|
||||
dimensions=$(identify -format "%wx%h" "$img")
|
||||
width=$(echo $dimensions | cut -d'x' -f1)
|
||||
height=$(echo $dimensions | cut -d'x' -f2)
|
||||
|
||||
# If width > 60 or height > 60, resize
|
||||
if [ "$width" -gt 60 ] || [ "$height" -gt 60 ]; then
|
||||
convert "$img" -resize 60x60 "$img"
|
||||
echo "Resized $img to 60x60"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to optimize images using pngquant
|
||||
optimize_images() {
|
||||
local img="$1"
|
||||
if [[ "$img" == *.png ]]; then
|
||||
pngquant --force --ext .png "$img"
|
||||
echo "Optimized $img using pngquant"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to resize images in the emotions folder to 40x40 if they are bigger
|
||||
resize_emotions_images() {
|
||||
local img="$1"
|
||||
local width height
|
||||
# Get the image dimensions
|
||||
dimensions=$(identify -format "%wx%h" "$img")
|
||||
width=$(echo $dimensions | cut -d'x' -f1)
|
||||
height=$(echo $dimensions | cut -d'x' -f2)
|
||||
|
||||
# If width > 40 or height > 40, resize
|
||||
if [ "$width" -gt 40 ] || [ "$height" -gt 40 ]; then
|
||||
mogrify -resize 40x40\> "$img"
|
||||
echo "Resized $img to 40x40"
|
||||
fi
|
||||
}
|
||||
|
||||
# Delete all files containing "_on" in the filename
|
||||
delete_files_with_on() {
|
||||
local img="$1"
|
||||
if [[ "$img" == *"_on"* ]]; then
|
||||
rm -f "$img"
|
||||
echo "Deleted $img"
|
||||
fi
|
||||
}
|
||||
|
||||
# Delete all Thumbs.db files recursively
|
||||
delete_thumbs_db() {
|
||||
find . -type f -iname "Thumbs.db" -exec rm -f {} \;
|
||||
echo "Deleted all Thumbs.db files"
|
||||
}
|
||||
|
||||
# Recursively find all image files except those in "emotions" directory
|
||||
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.gif" -o -iname "*.bmp" \) | while read -r img; do
|
||||
# Skip files in "emotions" folder
|
||||
if [[ "$img" == *"/emotions/"* ]]; then
|
||||
# Resize image in "emotions" folder if necessary
|
||||
resize_emotions_images "$img"
|
||||
continue
|
||||
fi
|
||||
|
||||
# Downscale image if necessary
|
||||
downscale_image "$img"
|
||||
done
|
||||
|
||||
# Resize the char_icon image to 60x60 if it's larger than that
|
||||
char_icon="char_icon"
|
||||
for ext in jpg jpeg png gif bmp; do
|
||||
if [ -f "$char_icon.$ext" ]; then
|
||||
resize_char_icon "$char_icon.$ext"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Optimize all images
|
||||
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.gif" -o -iname "*.bmp" \) | while read -r img; do
|
||||
optimize_images "$img"
|
||||
done
|
||||
|
||||
# Delete files containing "_on" in the filename
|
||||
find . -type f | while read -r img; do
|
||||
delete_files_with_on "$img"
|
||||
done
|
||||
|
||||
# Delete all Thumbs.db files recursively
|
||||
delete_thumbs_db
|
||||
|
||||
echo "Script completed!"
|
110
.scripts/optimizechar.sh
Executable file
110
.scripts/optimizechar.sh
Executable file
@ -0,0 +1,110 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Function to downscale images if they're larger than 960x544
|
||||
downscale_image() {
|
||||
local img="$1"
|
||||
local width height
|
||||
# Get the image dimensions
|
||||
dimensions=$(identify -format "%wx%h" "$img")
|
||||
width=$(echo $dimensions | cut -d'x' -f1)
|
||||
height=$(echo $dimensions | cut -d'x' -f2)
|
||||
|
||||
# If width > 960 or height > 544, resize
|
||||
if [ "$width" -gt 960 ] || [ "$height" -gt 544 ]; then
|
||||
mogrify -resize 960x544\> "$img"
|
||||
echo "Downscaled $img to 960x544"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to resize char_icon to 60x60 if it's bigger
|
||||
resize_char_icon() {
|
||||
local img="$1"
|
||||
local width height
|
||||
# Get the image dimensions
|
||||
dimensions=$(identify -format "%wx%h" "$img")
|
||||
width=$(echo $dimensions | cut -d'x' -f1)
|
||||
height=$(echo $dimensions | cut -d'x' -f2)
|
||||
|
||||
# If width > 60 or height > 60, resize
|
||||
if [ "$width" -gt 60 ] || [ "$height" -gt 60 ]; then
|
||||
convert "$img" -resize 60x60 "$img"
|
||||
echo "Resized $img to 60x60"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to optimize images using pngquant
|
||||
optimize_images() {
|
||||
local img="$1"
|
||||
if [[ "$img" == *.png ]]; then
|
||||
pngquant --force --ext .png "$img"
|
||||
echo "Optimized $img using pngquant"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to resize images in the emotions folder to 40x40 if they are bigger
|
||||
resize_emotions_images() {
|
||||
local img="$1"
|
||||
local width height
|
||||
# Get the image dimensions
|
||||
dimensions=$(identify -format "%wx%h" "$img")
|
||||
width=$(echo $dimensions | cut -d'x' -f1)
|
||||
height=$(echo $dimensions | cut -d'x' -f2)
|
||||
|
||||
# If width > 40 or height > 40, resize
|
||||
if [ "$width" -gt 40 ] || [ "$height" -gt 40 ]; then
|
||||
mogrify -resize 40x40\> "$img"
|
||||
echo "Resized $img to 40x40"
|
||||
fi
|
||||
}
|
||||
|
||||
# Delete all files containing "_on" in the filename
|
||||
delete_files_with_on() {
|
||||
local img="$1"
|
||||
if [[ "$img" == *"_on"* ]]; then
|
||||
rm -f "$img"
|
||||
echo "Deleted $img"
|
||||
fi
|
||||
}
|
||||
|
||||
# Delete all Thumbs.db files recursively
|
||||
delete_thumbs_db() {
|
||||
find . -type f -iname "Thumbs.db" -exec rm -f {} \;
|
||||
echo "Deleted all Thumbs.db files"
|
||||
}
|
||||
|
||||
# Recursively find all image files except those in "emotions" directory
|
||||
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.gif" -o -iname "*.bmp" \) | while read -r img; do
|
||||
# Skip files in "emotions" folder
|
||||
if [[ "$img" == *"/emotions/"* ]]; then
|
||||
# Resize image in "emotions" folder if necessary
|
||||
resize_emotions_images "$img"
|
||||
continue
|
||||
fi
|
||||
|
||||
# Downscale image if necessary
|
||||
downscale_image "$img"
|
||||
done
|
||||
|
||||
# Resize the char_icon image to 60x60 if it's larger than that
|
||||
char_icon="char_icon"
|
||||
for ext in jpg jpeg png gif bmp; do
|
||||
if [ -f "$char_icon.$ext" ]; then
|
||||
resize_char_icon "$char_icon.$ext"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Optimize all images
|
||||
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.gif" -o -iname "*.bmp" \) | while read -r img; do
|
||||
optimize_images "$img"
|
||||
done
|
||||
|
||||
# Delete files containing "_on" in the filename
|
||||
find . -type f | while read -r img; do
|
||||
delete_files_with_on "$img"
|
||||
done
|
||||
|
||||
# Delete all Thumbs.db files recursively
|
||||
delete_thumbs_db
|
||||
|
||||
echo "Script completed!"
|
Loading…
Reference in New Issue
Block a user