Skip to content

Commit 1642bb1

Browse files
committed
Improve screenshot processing for dark windows
1 parent a34097d commit 1642bb1

File tree

1 file changed

+39
-25
lines changed

1 file changed

+39
-25
lines changed

tools/process_image.sh

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,45 @@
11
#!/bin/sh
22

3-
TOPLEFT_COLOR=`magick $@ -format "%[hex:u.p{0,0}]\n" info:`
4-
if [ "$TOPLEFT_COLOR" = "00000000" ]
5-
then
6-
echo "Has top corners"
7-
TOP_CORNERS="( mpr:arc ) -gravity northwest -composite ( mpr:arc -flop ) -gravity northeast -composite"
3+
flag=$(identify -format '%[processed]' $@)
4+
if [ "$flag" = "true" ]; then
5+
echo "Skipping $@ (already processed)"
86
else
9-
echo "Does not have top corners"
10-
TOP_CORNERS=""
11-
fi
7+
echo "Process $@..."
128

13-
BORDER_COLOR=`magick $@ -format "%[hex:u.p{0,20}]\n" info:`
14-
if [ "$BORDER_COLOR" = "D3D3D3FF" ]
15-
then
16-
echo "Border already added, skipping."
17-
else
18-
convert $@ \
19-
\( +clone -alpha extract \
20-
\( -size 15x15 xc:black -draw 'fill white circle 15,15 15,0' -write mpr:arc +delete \) \
21-
$TOP_CORNERS \
22-
\) \
23-
-alpha off -compose CopyOpacity -composite -compose over \
24-
\( -clone 0 -fill "#D3D3D3FF" -colorize 100% \) \
25-
\( -clone 0 -alpha extract -virtual-pixel black -morphology edgein octagon:1 \) \
26-
-compose over -composite \
27-
\( +clone -background black \) \
28-
+swap -background none -layers merge +repage $@
9+
# Remove drop shadows (if any)
10+
#convert $@ -channel A -threshold 75% +channel -trim $@
11+
12+
# If it's a window, make rounded corners and add a window border.
13+
TOPLEFT_COLOR=`magick $@ -format "%[hex:u.p{0,0}]\n" info:`
14+
if [ "$TOPLEFT_COLOR" = "00000000" ]; then
15+
16+
# Extract left/right/bottom borders and convert light colors to border color
17+
convert $@ -alpha set -channel RGBA -fx 'i==0 || i==w-1 || j==h-1 ? u : transparent' \
18+
-colorspace HSL -channel lightness -separate +channel \
19+
-threshold 50% -transparent black -fill "#343434" -colorize 100% \
20+
"${@/.png/~1.png}"
21+
22+
# Overlay manual border colors with input image
23+
convert $@ "${@/.png/~1.png}" -composite $@
2924

25+
# Make nice round corners at top left and right
26+
convert $@ \
27+
\( +clone -alpha extract \
28+
\( -size 17x17 xc:black -draw 'fill white circle 17,17 17,0' -write mpr:arc +delete \) \
29+
\( mpr:arc \) -gravity northwest -composite \
30+
\( mpr:arc -flop \) -gravity northeast -composite \
31+
\) \
32+
-alpha off -compose CopyOpacity -composite -compose over \
33+
\( -clone 0 -fill "black" -colorize 100% \) \
34+
+swap -background none -layers merge +repage $@
35+
fi
36+
37+
# Remove temporary images
38+
rm "${@/.png/~1.png}"
39+
40+
# Reduce file size
3041
pngcrush -rem allb -brute -reduce -ow $@
31-
fi
42+
43+
# Set flag that this file has been processed
44+
convert $@ -set "processed" "true" $@
45+
fi

0 commit comments

Comments
 (0)