-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathblackify.sh
More file actions
executable file
·40 lines (33 loc) · 984 Bytes
/
blackify.sh
File metadata and controls
executable file
·40 lines (33 loc) · 984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
# Blackify - Convert colored images to black versions
# Usage: ./blackify.sh input.jpg [output.jpg]
if [ $# -lt 1 ]; then
echo "Usage: $0 <input_image> [output_image]"
echo "Example: $0 icon.jpg icon-black.jpg"
echo "If no output is specified, adds '-black' before the extension"
exit 1
fi
INPUT="$1"
# Check if input file exists
if [ ! -f "$INPUT" ]; then
echo "Error: Input file '$INPUT' does not exist"
exit 1
fi
# Generate output filename if not provided
if [ $# -eq 2 ]; then
OUTPUT="$2"
else
# Insert '-black' before the file extension
BASENAME="${INPUT%.*}"
EXTENSION="${INPUT##*.}"
OUTPUT="${BASENAME}-black.${EXTENSION}"
fi
# Convert blue (and other colors) to black using ImageMagick
echo "Converting '$INPUT' to '$OUTPUT'..."
magick "$INPUT" -fuzz 40% -fill black -opaque blue "$OUTPUT"
if [ $? -eq 0 ]; then
echo "Successfully created: $OUTPUT"
else
echo "Error: Failed to convert image"
exit 1
fi