Last active
December 19, 2015 10:59
-
-
Save maestrith/5944009 to your computer and use it in GitHub Desktop.
Upload an image to Imgur: Instructions Below:
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
#SingleInstance,force | |
Menu,Tray,Add | |
Menu,Tray,Add,Grab,grab | |
return | |
grab: | |
Hotkey,LButton,select,On | |
Hotkey,RButton,Select,On | |
Hotkey,^F1,getinfo,On | |
return | |
getinfo: | |
Gui,59:Destroy | |
Hotkey,LButton,Select,Off | |
Hotkey,RButton,Select,Off | |
filename=temp.bmp | |
CaptureScreen(filename) | |
IniRead,client,settings.ini,imgur,client,0 | |
if !(client){ | |
InputBox,client,Client not registered,If you do not already have an imgur api client registered press cancel`nYou can use an anonymous API`n`nIf you have a Client ID enter it below,,600 | |
if ErrorLevel | |
{ | |
Run,http://api.imgur.com/oauth2/addclient | |
return | |
} | |
IniWrite,%client%,settings.ini,imgur,client | |
} | |
http:=ComObjCreate("WinHttp.WinHttpRequest.5.1") | |
img:=ComObjCreate("WIA.ImageFile"),img.LoadFile(filename) | |
ip:=ComObjCreate("WIA.ImageProcess") | |
ip.filters.add(IP.FilterInfos("Crop").FilterID) | |
for a,b in select(1) | |
ip.filters(1).properties(a):=b | |
ip.filters.add(IP.FilterInfos("Convert").FilterID) | |
ip.filters(2).properties("FormatID").value:="{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}" | |
ip.filters(2).properties("Quality").value:=85 | |
img:=ip.apply(img) | |
data:=img.filedata.binarydata | |
http.Open("POST","https://api.imgur.com/3/upload") | |
http.SetRequestHeader("Authorization","Client-ID " client) | |
http.SetRequestHeader("Content-Length",size) | |
SplashTextOn,300,100,Uploading Image,Please wait... | |
http.Send(data),codes:=http.ResponseText | |
SplashTextOff | |
split=":" | |
RegExMatch(codes,"U)link" split "(.*)" chr(34),found) | |
Gui,3:Destroy | |
Gui,3:Add,Edit,w500 vcode,% RegExReplace(found1,"\\") | |
Gui,3:Add,Button,gcopy,Copy to Clipboard | |
Gui,3:Show,,Pasted Code | |
ControlSend,,^a,ahk_id%code% | |
return | |
copy: | |
Gui,3:Submit,NoHide | |
Clipboard:=code | |
MsgBox,The url for your image has been added to your clipboard. | |
return | |
CaptureScreen(sfile){ | |
;based on the code from http://www.autohotkey.com/board/topic/29449-gdi-standard-library-145-by-tic/page-28 | |
for a,b in {nl:76,nt:77,nw:78,nh:79} | |
SysGet,%a%,%b% | |
mDC:=DllCall("CreateCompatibleDC","Uint",0) | |
NumPut(VarSetCapacity(bi,40,0),bi) | |
NumPut(nW,bi,4),NumPut(nH,bi,8),NumPut(24,NumPut(1,bi,12,"UShort"),0,"Ushort"),NumPut(0,bi,16) | |
hbm:=DllCall("gdi32\CreateDIBSection","Uint",mDC,"Uint",&bi,"Uint",0,"UintP",pBits,"Uint",0,"Uint",0) | |
oBM:=DllCall("SelectObject","Uint",mDC,"Uint",hBM) | |
hDC:=DllCall("GetDC","Uint",0) | |
f:=DllCall("BitBlt","Uint",mDC,"int",0,"int",0,"int",nW,"int",nH,"Uint",hDC,"int",nL,"int",nT,"Uint",0x40000000|0x00CC0020) | |
DllCall("ReleaseDC","Uint",0,"Uint",hDC) | |
DllCall("SelectObject","Uint",mDC,"Uint",oBM) | |
DllCall("DeleteDC","Uint",mDC) | |
DllCall("GetObject","Uint",hBM,"int",VarSetCapacity(oi,84,0),"Uint",&oi) | |
hFile:=DllCall("CreateFile","Uint",&sFile,"Uint",0x40000000,"Uint",0,"Uint",0,"Uint",2,"Uint",0,"Uint",0) | |
DllCall("WriteFile","Uint",hFile,"int64P",0x4D42|14+40+NumGet(oi,44)<<16,"Uint",6,"UintP",0,"Uint",0) | |
DllCall("WriteFile","Uint",hFile,"int64P",54<<32,"Uint",8,"UintP",0,"Uint",0) | |
DllCall("WriteFile","Uint",hFile,"Uint",&oi+24,"Uint",40,"UintP",0,"Uint",0) | |
DllCall("WriteFile","Uint",hFile,"Uint",NumGet(oi,20),"Uint",NumGet(oi,44),"UintP",0,"Uint",0) | |
DllCall("CloseHandle","Uint",hFile) | |
DllCall("DeleteObject", "Uint", hbm) | |
} | |
select(get=""){ | |
static select,inside,pos | |
color:=color?color:0xff00ff | |
if get | |
return pos | |
CoordMode,Mouse,Screen | |
MouseGetPos,xx,yy,win | |
if !(xx>inside.x.MinIndex()&&xx<inside.x.MaxIndex()&&yy>inside.y.MinIndex()&&yy<inside.y.MaxIndex()) | |
Gui,59:Destroy | |
if !WinExist("ahk_id" select)&&A_ThisHotkey="rbutton" | |
return | |
if !WinExist("ahk_id" select){ | |
Gui,59:Destroy | |
Gui,59:Color,%color%,%color% | |
gui,59:show,x0 y0 w%A_ScreenWidth% h%A_ScreenHeight% noactivate hide | |
gui,59:-caption +hwndselect +ToolWindow +E0x20 +AlwaysOnTop | |
gui,59:show,NoActivate | |
WinSet,Transparent,80,ahk_id%select% | |
MouseGetPos,x,y | |
while,GetKeyState("LButton","P"){ | |
MouseGetPos,xx,yy | |
winset,region,%x%-%y% %x%-%yy% %xx%-%yy% %xx%-%y% %x%-%y%,ahk_id %select% | |
} | |
} | |
gui,59:color,%color% | |
if (xx>inside.x.MinIndex()&&xx<inside.x.MaxIndex()&&yy>inside.y.MinIndex()&&yy<inside.y.MaxIndex()&&GetKeyState("RButton","P")){ | |
x:=inside.x.MinIndex(),y:=inside.y.MinIndex() | |
while,GetKeyState("RButton","P"){ | |
MouseGetPos,xx,yy | |
w:=Abs((xx-minx)-x),h:=Abs((yy-miny)-y) | |
xx:=xx,yy:=yy | |
winset,region,%x%-%y% %x%-%yy% %xx%-%yy% %xx%-%y% %x%-%y%,ahk_id %select% | |
} | |
} | |
if (xx>inside.x.MinIndex()&&xx<inside.x.MaxIndex()&&yy>inside.y.MinIndex()&&yy<inside.y.MaxIndex()&&GetKeyState("LButton","P")){ | |
offsetx:=inside.x.MinIndex()-xx,offsety:=inside.y.MinIndex()-yy | |
box:=inside.x.MaxIndex()-inside.x.MinIndex(),boy:=inside.y.MaxIndex()-inside.y.MinIndex() | |
while,GetKeyState("LButton","P"){ | |
mousegetpos,ox,oy | |
x:=ox+offsetx,y:=oy+offsety,xx:=x+box,yy:=y+boy | |
winset,region,%x%-%y% %x%-%yy% %xx%-%yy% %xx%-%y% %x%-%y%,ahk_id %select% | |
} | |
} | |
inside:=[],pos:=[] | |
for a,b in [x,xx,y,yy] | |
inside[A_Index<3?"x":"y",b]:=1 | |
image.inside:=inside | |
for a in inside.x | |
pos[A_Index=1?"Left":"Right"]:=A_Index=1?a:A_ScreenWidth-a | |
for a in inside.y | |
pos[A_Index=1?"Top":"Bottom"]:=A_Index=1?a:A_ScreenHeight-a | |
return | |
select: | |
select() | |
return | |
} | |
m(x*){ | |
for a,b in x | |
list.=b "`n" | |
MsgBox,% list | |
} |
what are lines #28-35 are used for? are they mandatory?
especially lines #30-31 (in my code I've different selection, so I just removed that "for a,b in select(1)" since I didn't copy "select()" func.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Upload an image to Imgur To use:
a. Left click and move the selection if you need to adjust it
b. Right click and drag to resize the selection.