Post by tmplinshi » 22 Oct 2020, 00:39
如果你电脑上有装 ss, 那么使用
UploadToImgur(filename,, "localhost:1080")
上传图片到谷歌图片搜索:
Code: Select all
resultUrl := GoogleSearchByImage_Upload("C:\test.png", "localhost:1080")
Run, % resultUrl
GoogleSearchByImage_Upload(FileName, Proxy := "")
{
if !FileExist(FileName)
throw "file not exist"
CreateFormData( postData, contentType, {encoded_image: [FileName]} )
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
Proxy ? whr.SetProxy(2, Proxy) : ""
whr.Open("POST", "https://www.google.com/searchbyimage/upload", true)
whr.Option(6) := false ; 6 = WinHttpRequestOption_EnableRedirects
whr.SetRequestHeader("Content-Type", contentType)
whr.Send(postData)
whr.WaitForResponse()
if (whr.Status = 302)
return whr.GetResponseHeader("Location")
else
throw "upload failed"
}
GoogleSearchByImage_Url(ImageUrl)
{
return "https://www.google.com/searchbyimage?image_url=" . ImageUrl
}
; ===================================================================================
; CreateFormData() by tmplinshi, AHK Topic: https://autohotkey.com/boards/viewtopic.php?t=7647
; Thanks to Coco: https://autohotkey.com/boards/viewtopic.php?p=41731#p41731
; Modified version by SKAN, 09/May/2016
CreateFormData(ByRef retData, ByRef retHeader, objParam) {
New CreateFormData(retData, retHeader, objParam)
}
Class CreateFormData {
__New(ByRef retData, ByRef retHeader, objParam) {
Local CRLF := "`r`n", i, k, v, str, pvData
; Create a random Boundary
Local Boundary := this.RandomBoundary()
Local BoundaryLine := "------------------------------" . Boundary
this.Len := 0 ; GMEM_ZEROINIT|GMEM_FIXED = 0x40
this.Ptr := DllCall( "GlobalAlloc", "UInt",0x40, "UInt",1, "Ptr" ) ; allocate global memory
; Loop input paramters
For k, v in objParam
{
If IsObject(v) {
For i, FileName in v
{
str := BoundaryLine . CRLF
. "Content-Disposition: form-data; name=""" . k . """; filename=""" . FileName . """" . CRLF
. "Content-Type: " . this.MimeType(FileName) . CRLF . CRLF
this.StrPutUTF8( str )
this.LoadFromFile( Filename )
this.StrPutUTF8( CRLF )
}
} Else {
str := BoundaryLine . CRLF
. "Content-Disposition: form-data; name=""" . k """" . CRLF . CRLF
. v . CRLF
this.StrPutUTF8( str )
}
}
this.StrPutUTF8( BoundaryLine . "--" . CRLF )
; Create a bytearray and copy data in to it.
retData := ComObjArray( 0x11, this.Len ) ; Create SAFEARRAY = VT_ARRAY|VT_UI1
pvData := NumGet( ComObjValue( retData ) + 8 + A_PtrSize )
DllCall( "RtlMoveMemory", "Ptr",pvData, "Ptr",this.Ptr, "Ptr",this.Len )
this.Ptr := DllCall( "GlobalFree", "Ptr",this.Ptr, "Ptr" ) ; free global memory
retHeader := "multipart/form-data; boundary=----------------------------" . Boundary
}
StrPutUTF8( str ) {
Local ReqSz := StrPut( str, "utf-8" ) - 1
this.Len += ReqSz ; GMEM_ZEROINIT|GMEM_MOVEABLE = 0x42
this.Ptr := DllCall( "GlobalReAlloc", "Ptr",this.Ptr, "UInt",this.len + 1, "UInt", 0x42 )
StrPut( str, this.Ptr + this.len - ReqSz, ReqSz, "utf-8" )
}
LoadFromFile( Filename ) {
Local objFile := FileOpen( FileName, "r" )
this.Len += objFile.Length ; GMEM_ZEROINIT|GMEM_MOVEABLE = 0x42
this.Ptr := DllCall( "GlobalReAlloc", "Ptr",this.Ptr, "UInt",this.len, "UInt", 0x42 )
objFile.RawRead( this.Ptr + this.Len - objFile.length, objFile.length )
objFile.Close()
}
RandomBoundary() {
str := "0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z"
Sort, str, D| Random
str := StrReplace(str, "|")
Return SubStr(str, 1, 12)
}
MimeType(FileName) {
n := FileOpen(FileName, "r").ReadUInt()
Return (n = 0x474E5089) ? "image/png"
: (n = 0x38464947) ? "image/gif"
: (n&0xFFFF = 0x4D42 ) ? "image/bmp"
: (n&0xFFFF = 0xD8FF ) ? "image/jpeg"
: (n&0xFFFF = 0x4949 ) ? "image/tiff"
: (n&0xFFFF = 0x4D4D ) ? "image/tiff"
: "application/octet-stream"
}
}
如果你电脑上有装 ss, 那么使用 [c]UploadToImgur(filename,, "localhost:1080")[/c]
上传图片到谷歌图片搜索:
[Codebox=autohotkey file=GoogleSearchByImage.ahk]resultUrl := GoogleSearchByImage_Upload("C:\test.png", "localhost:1080")
Run, % resultUrl
GoogleSearchByImage_Upload(FileName, Proxy := "")
{
if !FileExist(FileName)
throw "file not exist"
CreateFormData( postData, contentType, {encoded_image: [FileName]} )
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
Proxy ? whr.SetProxy(2, Proxy) : ""
whr.Open("POST", "https://www.google.com/searchbyimage/upload", true)
whr.Option(6) := false ; 6 = WinHttpRequestOption_EnableRedirects
whr.SetRequestHeader("Content-Type", contentType)
whr.Send(postData)
whr.WaitForResponse()
if (whr.Status = 302)
return whr.GetResponseHeader("Location")
else
throw "upload failed"
}
GoogleSearchByImage_Url(ImageUrl)
{
return "https://www.google.com/searchbyimage?image_url=" . ImageUrl
}
; ===================================================================================
; CreateFormData() by tmplinshi, AHK Topic: https://autohotkey.com/boards/viewtopic.php?t=7647
; Thanks to Coco: https://autohotkey.com/boards/viewtopic.php?p=41731#p41731
; Modified version by SKAN, 09/May/2016
CreateFormData(ByRef retData, ByRef retHeader, objParam) {
New CreateFormData(retData, retHeader, objParam)
}
Class CreateFormData {
__New(ByRef retData, ByRef retHeader, objParam) {
Local CRLF := "`r`n", i, k, v, str, pvData
; Create a random Boundary
Local Boundary := this.RandomBoundary()
Local BoundaryLine := "------------------------------" . Boundary
this.Len := 0 ; GMEM_ZEROINIT|GMEM_FIXED = 0x40
this.Ptr := DllCall( "GlobalAlloc", "UInt",0x40, "UInt",1, "Ptr" ) ; allocate global memory
; Loop input paramters
For k, v in objParam
{
If IsObject(v) {
For i, FileName in v
{
str := BoundaryLine . CRLF
. "Content-Disposition: form-data; name=""" . k . """; filename=""" . FileName . """" . CRLF
. "Content-Type: " . this.MimeType(FileName) . CRLF . CRLF
this.StrPutUTF8( str )
this.LoadFromFile( Filename )
this.StrPutUTF8( CRLF )
}
} Else {
str := BoundaryLine . CRLF
. "Content-Disposition: form-data; name=""" . k """" . CRLF . CRLF
. v . CRLF
this.StrPutUTF8( str )
}
}
this.StrPutUTF8( BoundaryLine . "--" . CRLF )
; Create a bytearray and copy data in to it.
retData := ComObjArray( 0x11, this.Len ) ; Create SAFEARRAY = VT_ARRAY|VT_UI1
pvData := NumGet( ComObjValue( retData ) + 8 + A_PtrSize )
DllCall( "RtlMoveMemory", "Ptr",pvData, "Ptr",this.Ptr, "Ptr",this.Len )
this.Ptr := DllCall( "GlobalFree", "Ptr",this.Ptr, "Ptr" ) ; free global memory
retHeader := "multipart/form-data; boundary=----------------------------" . Boundary
}
StrPutUTF8( str ) {
Local ReqSz := StrPut( str, "utf-8" ) - 1
this.Len += ReqSz ; GMEM_ZEROINIT|GMEM_MOVEABLE = 0x42
this.Ptr := DllCall( "GlobalReAlloc", "Ptr",this.Ptr, "UInt",this.len + 1, "UInt", 0x42 )
StrPut( str, this.Ptr + this.len - ReqSz, ReqSz, "utf-8" )
}
LoadFromFile( Filename ) {
Local objFile := FileOpen( FileName, "r" )
this.Len += objFile.Length ; GMEM_ZEROINIT|GMEM_MOVEABLE = 0x42
this.Ptr := DllCall( "GlobalReAlloc", "Ptr",this.Ptr, "UInt",this.len, "UInt", 0x42 )
objFile.RawRead( this.Ptr + this.Len - objFile.length, objFile.length )
objFile.Close()
}
RandomBoundary() {
str := "0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z"
Sort, str, D| Random
str := StrReplace(str, "|")
Return SubStr(str, 1, 12)
}
MimeType(FileName) {
n := FileOpen(FileName, "r").ReadUInt()
Return (n = 0x474E5089) ? "image/png"
: (n = 0x38464947) ? "image/gif"
: (n&0xFFFF = 0x4D42 ) ? "image/bmp"
: (n&0xFFFF = 0xD8FF ) ? "image/jpeg"
: (n&0xFFFF = 0x4949 ) ? "image/tiff"
: (n&0xFFFF = 0x4D4D ) ? "image/tiff"
: "application/octet-stream"
}
}[/Codebox]