Created
November 14, 2013 09:06
-
-
Save dufferzafar/7463733 to your computer and use it in GitHub Desktop.
Upload Image to Imgur
This file contains hidden or 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
#SingleInstance, Force | |
; #Include json.inc.ahk | |
imgurClient := "a7c30de4f98751b" | |
File := FileOpen("screen.png", "r") | |
File.RawRead(Data, File.Length) | |
Base64enc( PNGDATA, Data, File.Length ) | |
http := ComObjCreate("WinHttp.WinHttpRequest.5.1") | |
http.Open("POST","https://api.imgur.com/3/upload") | |
http.SetRequestHeader("Authorization","Client-ID " imgurClient) | |
SplashTextOn,,,Uploading Image,Please wait... | |
http.Send(PNGDATA) | |
codes := http.ResponseText | |
SplashTextOff | |
; FileRead, codes, Output.json | |
; Msgbox, % codes | |
Msgbox, % json(codes, "success") | |
Msgbox, % RegExReplace(json(codes, "data.link"),"\\") | |
Return | |
Base64enc( ByRef OutData, ByRef InData, InDataLen ) { | |
DllCall( "Crypt32.dll\CryptBinaryToString" ( A_IsUnicode ? "W" : "A" ) | |
, UInt,&InData, UInt,InDataLen, UInt,1, UInt,0, UIntP,TChars, "CDECL Int" ) | |
VarSetCapacity( OutData, Req := TChars * ( A_IsUnicode ? 2 : 1 ) ) | |
DllCall( "Crypt32.dll\CryptBinaryToString" ( A_IsUnicode ? "W" : "A" ) | |
, UInt,&InData, UInt,InDataLen, UInt,1, Str,OutData, UIntP,Req, "CDECL Int" ) | |
Return TChars | |
} | |
/* | |
Function: JSON | |
Parameters: | |
js - source | |
s - path to element | |
v - (optional) value to overwrite | |
Returns: | |
Value of element (prior to change). | |
License: | |
- Version 2.0 <http://www.autohotkey.net/~polyethene/#json> | |
- Dedicated to the public domain (CC0 1.0) <http://creativecommons.org/publicdomain/zero/1.0/> | |
*/ | |
json(ByRef js, s, v = "") { | |
j = %js% | |
Loop, Parse, s, . | |
{ | |
p = 2 | |
RegExMatch(A_LoopField, "([+\-]?)([^[]+)((?:\[\d+\])*)", q) | |
Loop { | |
If (!p := RegExMatch(j, "(?<!\\)(""|')([^\1]+?)(?<!\\)(?-1)\s*:\s*((\{(?:[^{}]++|(?-1))*\})|(\[(?:[^[\]]++|(?-1))*\])|" | |
. "(?<!\\)(""|')[^\7]*?(?<!\\)(?-1)|[+\-]?\d+(?:\.\d*)?|true|false|null?)\s*(?:,|$|\})", x, p)) | |
Return | |
Else If (x2 == q2 or q2 == "*") { | |
j = %x3% | |
z += p + StrLen(x2) - 2 | |
If (q3 != "" and InStr(j, "[") == 1) { | |
StringTrimRight, q3, q3, 1 | |
Loop, Parse, q3, ], [ | |
{ | |
z += 1 + RegExMatch(SubStr(j, 2, -1), "^(?:\s*((\[(?:[^[\]]++|(?-1))*\])|(\{(?:[^{\}]++|(?-1))*\})|[^,]*?)\s*(?:,|$)){" . SubStr(A_LoopField, 1) + 1 . "}", x) | |
j = %x1% | |
} | |
} | |
Break | |
} | |
Else p += StrLen(x) | |
} | |
} | |
If v != | |
{ | |
vs = " | |
If (RegExMatch(v, "^\s*(?:""|')*\s*([+\-]?\d+(?:\.\d*)?|true|false|null?)\s*(?:""|')*\s*$", vx) | |
and (vx1 + 0 or vx1 == 0 or vx1 == "true" or vx1 == "false" or vx1 == "null" or vx1 == "nul")) | |
vs := "", v := vx1 | |
StringReplace, v, v, ", \", All | |
js := SubStr(js, 1, z := RegExMatch(js, ":\s*", zx, z) + StrLen(zx) - 1) . vs . v . vs . SubStr(js, z + StrLen(x3) + 1) | |
} | |
Return, j == "false" ? 0 : j == "true" ? 1 : j == "null" or j == "nul" | |
? "" : SubStr(j, 1, 1) == """" ? SubStr(j, 2, -1) : j | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment