-
Notifications
You must be signed in to change notification settings - Fork 0
/
ptpx.sh
executable file
·41 lines (36 loc) · 858 Bytes
/
ptpx.sh
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
41
#!/bin/bash
# Default DPI for 1080p
DPI=96
# Parse command line arguments
while getopts ":d:" opt; do
case ${opt} in
d )
# Get the dimensions
dimensions=$OPTARG
# Split the dimensions into width and height
IFS='x' read -ra SIZE <<< "$dimensions"
# Calculate the DPI (assuming a 21.5" monitor)
DPI=$(echo "sqrt(${SIZE[0]}^2 + ${SIZE[1]}^2) / 21.5" | bc)
;;
\? )
echo "Invalid option: -$OPTARG" 1>&2
exit 1
;;
: )
echo "Option -$OPTARG requires an argument." 1>&2
exit 1
;;
esac
done
shift $((OPTIND -1))
# Check if argument is provided
if [ -z "$1" ]
then
echo "Please provide a point value as an argument."
exit 1
fi
# Calculate px from pt
PT=$1
PX=$(echo "$PT * $DPI / 72" | bc)
echo "${PT}pt = ${PX}px (copied to clipboard)"
echo "${PX}px" | pbcopy