Bagheera Bghira commited on
Commit ·
712958f
1
Parent(s): bea0389
scripts
Browse files- scripts/khoya.sh +28 -0
- scripts/resize.sh +22 -0
scripts/khoya.sh
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
#
|
| 4 |
+
# Pull captions from filenames and make them suitable for use by Khoya trainer.
|
| 5 |
+
#
|
| 6 |
+
|
| 7 |
+
# Directory containing the .png files
|
| 8 |
+
png_directory="/path/to/png_files"
|
| 9 |
+
|
| 10 |
+
# Directory to save the .txt files
|
| 11 |
+
txt_directory="/path/to/txt_files"
|
| 12 |
+
|
| 13 |
+
# Create the txt_directory if it doesn't exist
|
| 14 |
+
mkdir -p "$txt_directory"
|
| 15 |
+
|
| 16 |
+
# Loop through each .png file in the png_directory
|
| 17 |
+
for png_file in "$png_directory"/*.png; do
|
| 18 |
+
# Extract the filename without the extension
|
| 19 |
+
base_name=$(basename "$png_file" .png)
|
| 20 |
+
|
| 21 |
+
# Replace underscores with spaces
|
| 22 |
+
txt_content="${base_name//_/ }"
|
| 23 |
+
|
| 24 |
+
# Create a .txt file with the same name and write the content
|
| 25 |
+
echo "$txt_content" > "$txt_directory/${base_name}.txt"
|
| 26 |
+
done
|
| 27 |
+
|
| 28 |
+
echo "TXT files created in $txt_directory"
|
scripts/resize.sh
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
resize_image() {
|
| 4 |
+
img="$1"
|
| 5 |
+
# Get image dimensions
|
| 6 |
+
dimensions=$(identify -format "%wx%h" "$img")
|
| 7 |
+
width=$(echo $dimensions | cut -dx -f1)
|
| 8 |
+
height=$(echo $dimensions | cut -dx -f2)
|
| 9 |
+
|
| 10 |
+
# Calculate new dimensions
|
| 11 |
+
if (( width < height )); then
|
| 12 |
+
new_dim="1024x"
|
| 13 |
+
else
|
| 14 |
+
new_dim="x1024"
|
| 15 |
+
fi
|
| 16 |
+
|
| 17 |
+
# Resize image with new dimensions
|
| 18 |
+
convert "$img" -resize "$new_dim" -filter Lanczos -antialias "${img%.*}_resized.png"
|
| 19 |
+
}
|
| 20 |
+
export -f resize_image
|
| 21 |
+
|
| 22 |
+
find /path/to/source/ | parallel -j$(nproc) resize_image {}
|