Own screenshot sharing service (on the knee in 20 minutes)

    Good afternoon% habr%

    Working in the JIRA / Redmine / basecamp / Wiki, there’s a familiar way of inserting an image :! Http: //blah.com/img.png! But free services, to one degree or another, do not allow working effectively.

    Clip2net, for example, does not provide a direct link to a file, and it takes time to erase it from the page if there are 20 screenshots and each needs a URL ...

    Gyazo on a free account is limited in time of use, the URL has to be modified by appending ".png" at the end , the pictures have a limited shelf life, and gyazo ads beyond which it is already difficult to find the screen itself is something.

    The thought to use Dropbox prompted this comment. The idea seemed interesting to me and I sat down on my bike. DIY implementation of the "service" and the client part, with its pros and cons, under the cut.



    Requirements


    • Hot Key Launch
    • Arbitrary area selection
    • File name (like gyazo) as an MD5 hash
    • Direct link to clipboard file
    • PNG image format
    • Ability to change settings

    Logics


    • System hotkey hook
    • Launch a screenshot app
    • Mark area
    • Get the MD5 hash of the current timestamp
    • Save file to Dropbox public folder
    • Put link to file on clipboard

    Instruments


    • Dropbox - the famous file storage and synchronization service
    • autoit - a task automation tool for Windows
    • MiniCap - application for creating screenshots (understands the command line)

    Configuration is done through editing config.ini in the directory with the program:
    config.ini
    [MAIN]
    ; куда сохранять файлы скринов
    DBOX_DIR = "C:\Dropbox\Public\pic\"
    ; путь до приложения создающего скриншоты
    CAP = "C:\Program Files\MiniCap\MiniCap.exe"
    ; часть внешнй ссылки (можно получить на странице Dropbox)
    ; пример http://dl.dropbox.com/u/2058666/pic/1c40b047e22875c8396b029b00ea9a14.png
    DBOX_URL = "http://dl.dropbox.com/u/2058666/pic/"
    ; hotkey по которому делаем скриншот
    shoot_key = "{PRINTSCREEN}"
    


    Actually, AutoIT script:
    BoxShoot.au3
    #include  
    $hotkey 	= IniRead("config.ini", "MAIN", "shoot_key", "NotFound")
    $DBOX_DIR 	= IniRead("config.ini", "MAIN", "DBOX_DIR", "NotFound")
    $DBOX_URL 	= IniRead("config.ini", "MAIN", "DBOX_URL", "NotFound")
    $CAP 		= IniRead("config.ini", "MAIN", "CAP", "NotFound")
    HotKeySet ( $hotkey, "SHOOT" )
    TraySetToolTip("BoxShoot")
    Opt("TrayMenuMode", 1)
    $exititem = TrayCreateItem("Exit")
    TraySetState()
    While 1
        $msg = TrayGetMsg()
        Select
            Case $msg = 0
                ContinueLoop
            Case $msg = $exititem
                CLOSE()
        EndSelect
    WEnd
    Func SHOOT()
    	$CurTime = @YEAR & "_" & @MON & "_" & @MDAY & "_" & @HOUR & "_" & @MIN & "_" & @SEC
    	$hash = _Crypt_HashData($CurTime, $CALG_MD5)
    	$result = StringTrimLeft($hash, 2)
    	$fname = $result & ".png"
    	$fname = StringLower($fname) 
    	Run($CAP & " -captureregselect -exit -compress 7 -bordershadow -noaero -save " & $DBOX_DIR & $fname , "", @SW_MINIMIZE)
    	ClipPut($DBOX_URL & $fname)
    EndFunc
    Func CLOSE()
    	Exit 0
    EndFunc
    

    After starting, the program hangs in the tray, waiting for pressing PrintScreen.

    It takes up 1.5mb in memory

    Auto start - in manual mode, that is, through creating a shortcut in the "Start - Startup"


    Statistics



    Files: ~ 400
    Volume: ~ 17mb
    I have been using it since October 31.

    I’m almost completely satisfied, the links do not look very nice, I’m thinking of screwing the URL shortener.

    Bonus


    Using scrot, xclip and a bit of Bash scripting - you can easily get an analog for your favorite * nix:
    #!/bin/bash
    F_NAME=`date +%s | md5sum | awk '{ print $1}'`'.png'
    DBOX_DIR='/home/username/Dropbox/Public/pic/'
    DBOX_URL='http://dl.dropbox.com/u/2058666/pic/'
    S_NAME=$DBOX_DIR$F_NAME
    scrot -s -q 0 $S_NAME
    echo -n $DBOX_URL$F_NAME | xclip
    

    It remains to fasten XBindKeys.

    Source code and ready exe are available on GitHub

    PS


    DropBox ID changed for security reasons, I apologize to the poor fellow, whose ID appears in the scripts.

    Also popular now: