Last active
March 28, 2018 16:21
-
-
Save Cygon/fa7e91a24ae5e870152cc3a43c453bb0 to your computer and use it in GitHub Desktop.
Takes a screenshot of a predefined area of the desktop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Takes a screenshot of a predefined area of your desktop | |
# Good for comparison images and making animations where FPS is too low for OBS | |
# | |
# Dependencies: | |
# - scrot | |
# - graphicsmagick | |
# Change these values to match your preferences | |
imageQuality=100 # scrot default is 75 | |
screenshotDir="." # directory in which to save screenshots | |
# Capture area | |
# -> main screen without title bar and task bar = 1920, 37, 2560, 1330 | |
default_left=1920 # begin crop this number of pixels from the left of the image | |
default_top=37 # begin crop this number of pixels from the top of the image | |
default_width=2560 # crop this many pixels wide | |
default_height=1330 # crop this many pixels tall | |
# Allow override of capture rectangle specified from the command line | |
l=$1; t=$2; w=$3; h=$4 | |
left=${l:=$default_left} | |
top=${t:=$default_top} | |
width=${w:=$default_width} | |
height=${h:=$default_height} | |
# Look for next free filename in sequence | |
i=1 | |
imagePath=$screenshotDir/screenshot-$(printf "%04d" $i).png | |
while [[ -e $screenshotDir/screenshot-$(printf "%04d" $i).png ]] ; do | |
let i++ | |
done | |
imagePath=$screenshotDir/screenshot-$(printf "%04d" $i).png | |
# Do the screenshottery | |
# Crop will capture everything, so we'll export to .bmp (fast loading/saving), | |
# then use GraphicsMagick to crop and convert to .png | |
[ ! -d "$screenshotDir" ] && mkdir -p "$screenshotDir" | |
scrot -q $imageQuality "/tmp/screenshot.bmp" | |
gm convert "/tmp/screenshot.bmp" -crop ${width}x${height}+${left}+${top} "$imagePath" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment