├── terminal.gif ├── LICENSE ├── README.md └── kgif.sh /terminal.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luminousmen/Kgif/HEAD/terminal.gif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Kirill Bobrov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![FBI](https://img.shields.io/badge/%F0%9F%95%B5-FBI%20checked-green.svg)](https://www.fbi.gov/) 2 | [![bug free](https://img.shields.io/badge/%F0%9F%90%9B-bug%20free-green.svg)](https://en.wikipedia.org/wiki/Software_bug) 3 | 4 | Kgif 5 | ====== 6 | 7 | Tool for creating gif file from capturing active window. 8 | 9 | ![gif](https://camo.githubusercontent.com/38df9b507042dded48415dbb5a5a3c4966ea324c/687474703a2f2f692e696d6775722e636f6d2f3965743864614e2e6a7067) 10 | 11 | Originally it was created for capturing tty output and creating preview for github projects :wink: 12 | 13 | 14 | I needed to capture tty output on my Ubuntu 15.10. First I came up to using ```ttyrec``` with [ttygif](https://github.com/icholy/ttygif) or [tty2gif](https://bitbucket.org/antocuni/tty2gif) convertor, then find [showterm.io](http://showterm.io/). All this solutions didn't work for me :grimacing: Than I create this simple script that satisfies all my needs. 15 | 16 | ### Dependencies 17 | 18 | * scrot 19 | * imagemagick 20 | 21 | 22 | ### Installation 23 | 24 | ```bash 25 | $ sudo apt-get install imagemagick scrot 26 | $ git clone https://github.com/luminousmen/Kgif 27 | ``` 28 | 29 | ### Usage 30 | 31 | ```bash 32 | $ ./kgif.sh --help 33 | usage: ./kgif.sh [--delay] [--filename ] [--gifdelay] [--noclean] [--check] [-h] 34 | -h, --help Show this help, exit 35 | --check Check if all dependencies are installed, exit 36 | --delay= Set delay in seconds to specify how long script will wait until start capturing. 37 | --gifdelay= Set delay in seconds to specify how fast images appears in gif. 38 | --filename= Set file name for output gif. 39 | --noclean Set if you don't want to delete source *.png screenshots. 40 | 41 | ``` 42 | 43 | Check if all dependencies presents in system: 44 | ```bash 45 | $ ./kgif.sh --check 46 | ``` 47 | 48 | Set ```delay``` in seconds to specify how long script will wait until start capturing. 49 | ```bash 50 | $ ./kgif.sh --delay=5 51 | ``` 52 | 53 | Set ```noclean``` if you don't want to delete source png screenshots (for example if you want to delete some of the screenshots). 54 | ```bash 55 | $ ./kgif.sh --delay=5 --noclean 56 | ``` 57 | 58 | ### Preview 59 | 60 | ![preview](terminal.gif) 61 | -------------------------------------------------------------------------------- /kgif.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (c) 2016, Bobrov Kirill 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # 9 | # * Redistributions of source code must retain the above copyright notice, 10 | # this list of conditions and the following disclaimer. 11 | # * Redistributions in binary form must reproduce the above copyright 12 | # notice, this list of conditions and the following disclaimer in the 13 | # documentation and/or other materials provided with the distribution. 14 | # 15 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY 16 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY 19 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25 | # DAMAGE. 26 | 27 | 28 | NOCLEAN=false 29 | # capturing delay 30 | SCROT_DELAY=0.5 31 | # delay in gif 32 | GIF_DELAY=1 33 | # output gif file 34 | GIF_FILENAME="terminal.gif" 35 | # clean tmp directory 36 | 37 | usage() { 38 | echo "usage: ./kgif.sh [--delay] [--filename ] [--gifdelay] [--noclean] [--check] [-h]" 39 | echo " -h, --help Show this help, exit" 40 | echo " --check Check if all dependencies are installed, exit" 41 | echo " --delay= Set delay in seconds to specify how long script will wait until start capturing." 42 | echo " --gifdelay= Set delay in seconds to specify how fast images appears in gif." 43 | echo " --filename= Set file name for output gif." 44 | echo " --noclean Set if you don't want to delete source *.png screenshots." 45 | echo "" 46 | } 47 | 48 | ctrlc() { 49 | printf "\\nStop capturing" 50 | 51 | echo "Converting to gif..." 52 | convert -quiet -delay $GIF_DELAY -loop 0 -- *.png ../$GIF_FILENAME 53 | cd .. 54 | 55 | if [ "$NOCLEAN" = false ] ; then 56 | echo "Cleaning..." 57 | clean 58 | fi 59 | 60 | echo "Done!" 61 | exit 2 62 | } 63 | 64 | clean() { 65 | rm -rf "$NOW" 66 | } 67 | 68 | capturing() { 69 | echo "Capturing..." 70 | cd ./"$NOW" || exit 71 | while true 72 | do 73 | scrot -u -d $SCROT_DELAY 74 | done 75 | } 76 | 77 | dependency_check() { 78 | (which scrot > /dev/null 2>&1 && echo "OK: found scrot") || echo "ERROR: scrot not found" 79 | (which convert > /dev/null 2>&1 && echo "OK: found imagemagick") || echo "ERROR: imagemagick not found" 80 | exit 2 81 | } 82 | 83 | while [ "$1" != "" ]; do 84 | PARAM=$(echo "$1" | awk -F= '{print $1}') 85 | VALUE=$(echo "$1" | awk -F= '{print $2}') 86 | case $PARAM in 87 | -h | --help) 88 | usage 89 | exit 90 | ;; 91 | --delay) 92 | DELAY=$VALUE 93 | ;; 94 | --gifdelay) 95 | GIF_DELAY=$VALUE 96 | ;; 97 | --filename) 98 | GIF_FILENAME=$VALUE 99 | echo "Out file - $GIF_FILENAME" 100 | ;; 101 | --noclean) 102 | NOCLEAN=true 103 | echo "NOCLEAN mode enabled" 104 | ;; 105 | --check) 106 | CHECK=true 107 | ;; 108 | *) 109 | echo "ERROR: unknown parameter \"$PARAM\"" 110 | usage 111 | exit 1 112 | ;; 113 | esac 114 | shift 115 | done 116 | 117 | 118 | # main() 119 | 120 | # dependency check 121 | if [ "$CHECK" = true ] ; then 122 | dependency_check 123 | fi 124 | 125 | trap "ctrlc" INT TERM 126 | 127 | NOW=$(date +"%m-%d-%Y_%H:%M:%S") 128 | if [ ! -d ./"$NOW" ]; then 129 | mkdir ./"$NOW" 130 | fi 131 | 132 | # if no delay passing 133 | if test -z "$DELAY" ; then 134 | DELAY=1 135 | fi 136 | 137 | echo "Setting delay to $DELAY sec" 138 | echo "" 139 | 140 | # wait for a while 141 | sleep $DELAY 142 | 143 | capturing 144 | --------------------------------------------------------------------------------