1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/nimeiz-paste_image

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
paste_image.ahk 3.8 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
nimeiz Отправлено 08.04.2019 18:14 0faaaf0
IfExist, .\config.ini
{
IniRead, zip, .\config.ini, config, Zip
IniRead, saveHere, .\config.ini, config, SaveHere
IniRead, urlPrefix, .\config.ini, config, UrlPrefix
IniRead, isDebug, .\config.ini, config, IsDebug
}
else
{
MsgBox config.ini not found.
return
}
working_dir = %A_ScriptDir%\
if (isDebug = "yes")
{
isDebug = /k
}
else
{
isDebug = /c
}
IsImg(ft)
{
if (ft = "gif" or ft = "png" or ft = "jpg") {
return true
}else{
MsgBox, 额,itsntImg,俺目前只能支持png、gif、jpg后缀的文件呢
return false
}
}
ZipImg(ft, debug)
{
SetWorkingDir, %working_dir%
; MsgBox, %ft%
if (ft="gif")
{
RunWait, %comspec% %debug% gifsicle.exe -O2 --colors=64 --use-col=web tteemmpp.gif > zip-tteemmpp.gif
}
else if (ft = "png")
{
RunWait, %comspec% %debug% pngquant.exe --output zip-tteemmpp.png -- tteemmpp.png
}
else if (ft = "jpg")
{
RunWait, %comspec% %debug% moz-cjpeg.exe -outfile zip-tteemmpp.jpg tteemmpp.jpg
}
else
{
MsgBox, 额,俺目前只能支持png、gif、jpg后缀的文件呢
return
}
}
GUID()
{
format = %A_FormatInteger% ; save original integer format
SetFormat Integer, Hex ; for converting bytes to hex
VarSetCapacity(A,16)
DllCall("rpcrt4\UuidCreate","Str",A)
Address := &A
Loop 16
{
x := 256 + *Address ; get byte in hex, set 17th bit
StringTrimLeft x, x, 3 ; remove 0x1
h = %x%%h% ; in memory: LS byte first
Address++
}
SetFormat Integer, %format% ; restore original format
;h := SubStr(h,1,8) . "-" . SubStr(h,9,4) . "-" . SubStr(h,13,4) . "-" . SubStr(h,17,4) . "-" . SubStr(h,21,12)
return h
}
#!space::
InputBox, setup, 设置... , `nD:`t开头的 设置图片在本地保存的路径,比如D:\images`n/`t开头的 设置生成的相对路径,比如/images`nnozip`t图片不用压缩`t`tzip`t图片压缩`n------------------------------------------------------`n`n%saveHere%`n%urlPrefix%`nzip:%zip%`t%isDebug%,,460,260
if ErrorLevel
return
if (RegExMatch(setup,"i)^[C-Z]:"))
{
saveHere = %setup%
}
if (RegExMatch(setup, "^/"))
{
urlPrefix = %setup%
}
if (setup="nozip")
{
zip = no
}
if (setup="zip")
{
zip = yes
}
if (setup="debug")
{
isDebug=/k
}
if (setup="run")
{
isDebug=/c
}
MsgBox, --------------------------------`n%saveHere%`n%urlPrefix%`nzip:%zip%`t%isDebug%
return
#!v::
guid := GUID()
if(clipboard)
{
;;;;; get file type by extension
clipboardStr = %clipboard%
StringSplit, ColorArray, clipboardStr, `. ;split by '.'
maxIndex := ColorArray0 ;get array lenth
str = ColorArray%maxIndex%
fileType := ColorArray%maxIndex% ;get last element of array, namely file type or file extension
tempFName = %working_dir%tteemmpp.%fileType% ;临时文件名
zipTempFName = %working_dir%zip-tteemmpp.%fileType% ;压缩后的临时文件名
imgName = %guid%.%fileType% ;图片文件名
fName = %saveHere%\%imgName% ;保存图片的全路径
if(IsImg(fileType))
{
SetWorkingDir, %working_dir%
fileCopy, %clipboard%, %tempFName%,1
if(zip="yes")
{
ZipImg(fileType, isDebug)
IfExist, %zipTempFName%
{
FileDelete, %tempFName%
FileCopy, %zipTempFName%, %fName%
FileDelete, %zipTempFName%
}
}
else
{
FileCopy, %tempFName%, %fName%
FileDelete, %tempFName%
}
}
else return
}
else
{
SetWorkingDir, %working_dir%
pathAndName = %saveHere%\%guid%.png
imgName = %guid%.png
gid := GUID()
filename = %saveHere%\%gid%.png
RunWait, %comspec% %isDebug% powershell set-executionpolicy remotesigned && powershell -sta -f dump-clipboard-png.ps1 %pathAndName%
if (zip = "yes")
{
RunWait, %comspec% %isDebug% pngquant.exe --output %filename% -- %pathAndName%
FileDelete, %pathAndName%
imgName = %gid%.png
}
}
imgUrl = ![](%urlPrefix%/%imgName%)
;MsgBox, %imgUrl%
clipboard = ; Empty the clipboard.
clipboard = %imgUrl%
;MsgBox %clipboard%
Send ^v
return

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/nimeiz-paste_image.git
git@api.gitlife.ru:oschina-mirror/nimeiz-paste_image.git
oschina-mirror
nimeiz-paste_image
nimeiz-paste_image
master