This commit is contained in:
Strix 2024-06-02 19:02:43 +02:00
commit d38b9f1ab0
6 changed files with 89 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
**/mutations

23
README.md Normal file
View file

@ -0,0 +1,23 @@
# Assets
## Saluco
![](./logos/saluco/saluco-white.png)
![](./logos/saluco/saluco-black.png)
### Derivatives
Created with `./scale ./logos/saluco`
> If you see nothing here, the derivatives weren't generated.
![](./logos/saluco/mutations/saluco-white/saluco-white_35.png)
![](./logos/saluco/mutations/saluco-black/saluco-black_35.png)
![](./logos/saluco/mutations/saluco-white/saluco-white_70.png)
![](./logos/saluco/mutations/saluco-black/saluco-black_70.png)
![](./logos/saluco/mutations/saluco-white/saluco-white_140.png)
![](./logos/saluco/mutations/saluco-black/saluco-black_140.png)
![](./logos/saluco/mutations/saluco-white/saluco-white_280.png)
![](./logos/saluco/mutations/saluco-black/saluco-black_280.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

BIN
logos/saluco/saluco.xcf Normal file

Binary file not shown.

65
scale Executable file
View file

@ -0,0 +1,65 @@
#!/bin/bash
# Default heights to scale images to
DEFAULT_HEIGHTS=(35 70 140 280)
# Function to resize image while maintaining aspect ratio
resize_image() {
local input_file="$1"
local height="$2"
local filename=$(basename "$input_file")
local dirname=$(dirname "$input_file")
local extension="${filename##*.}"
local name="${filename%.*}"
echo "$dirname" | grep -q "mutations" && return 1
# Create the derivatives directory if it doesn't exist
local output_dir="${dirname}/mutations/${name}"
mkdir -p "$output_dir"
local output_file="${output_dir}/${name}_${height}.${extension}"
# Check if the output file already exists
if [[ ! -f "$output_file" ]]; then
# Use convert (ImageMagick) to resize the image
convert "$input_file" -resize "x${height}" "$output_file"
echo "Resized $input_file to $output_file"
else
echo "Skipped $input_file, $output_file already exists"
fi
}
# Function to process directory recursively
process_directory() {
local dir="$1"
local heights=("${!2}")
find "$dir" -type d -name "*_derivatives" -prune -o -type f \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' -o -iname '*.gif' -o -iname '*.bmp' \) -print | while read -r file; do
for height in "${heights[@]}"; do
resize_image "$file" "$height"
done
done
}
# Main function
main() {
local target_dir="$1"
shift
local heights=("$@")
if [[ -z "$target_dir" ]]; then
echo "Usage: $0 <directory> [heights...]"
exit 1
fi
if [[ ${#heights[@]} -eq 0 ]]; then
heights=("${DEFAULT_HEIGHTS[@]}")
fi
process_directory "$target_dir" heights[@]
}
# Call the main function with all script arguments
main "$@"