As far as I can determine AutoHotkey Gui's do not support webp image format.
As far as I can determine Windows 10 does not have built-in support for WebP
Does this mean that Autohotkey can not support webp until Windows 10 has built in support for webp ?
Gui support for webp image format Topic is solved
Gui support for webp image format
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
Re: Gui support for webp image format
Upon further research I have found that if you remove the -rwa from the end of the url and use UrlDownLoadToFile to download the file, it can be displayed by an AutoHotkey Gui. becomes
I tried many ways to right click and choose Save Image As with Chrome and could not get the downloaded image to display in a GUI.
I have not tried to download the image with any other browsers.
Code: Select all
URLDownloadToFile,https://lh3.googleusercontent.com/BdQ1ngugnmV6uT960KOX0G9av7YJF4MnoEdSgi5xBINEC4YYuOp3Q7RUj7i4Cg0tRQ=w884-rwa,Webp-Image.webp
Code: Select all
URLDownloadToFile,https://lh3.googleusercontent.com/BdQ1ngugnmV6uT960KOX0G9av7YJF4MnoEdSgi5xBINEC4YYuOp3Q7RUj7i4Cg0tRQ=w884,Webp-Image.webp
I have not tried to download the image with any other browsers.
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
-
- Posts: 1472
- Joined: 05 May 2018, 12:23
Re: Gui support for webp image format
?DataLife wrote: ↑17 Jul 2019, 21:31Upon further research I have found that if you remove the -rwa from the end of the url and use UrlDownLoadToFile to download the file, it can be displayed by an AutoHotkey Gui.
I tried many ways to right click and choose Save Image As with Chrome and could not get the downloaded image to display in a GUI.
Re: Gui support for webp image format
You actually download a png file after removing the -rwa from the end of the url.DataLife wrote: ↑17 Jul 2019, 21:31Upon further research I have found that if you remove the -rwa from the end of the url and use UrlDownLoadToFile to download the file, it can be displayed by an AutoHotkey Gui.becomesCode: Select all
URLDownloadToFile,https://lh3.googleusercontent.com/BdQ1ngugnmV6uT960KOX0G9av7YJF4MnoEdSgi5xBINEC4YYuOp3Q7RUj7i4Cg0tRQ=w884-rwa,Webp-Image.webp
I tried many ways to right click and choose Save Image As with Chrome and could not get the downloaded image to display in a GUI.Code: Select all
URLDownloadToFile,https://lh3.googleusercontent.com/BdQ1ngugnmV6uT960KOX0G9av7YJF4MnoEdSgi5xBINEC4YYuOp3Q7RUj7i4Cg0tRQ=w884,Webp-Image.webp
I have not tried to download the image with any other browsers.
Re: Gui support for webp image format
These are the other possible URL endings that need to be removed to down webp images as png.
-rw
-rw-no
-rwa
Does anyone know if ALL webp image urls will end in one of these 3 possibilities?
Maybe just Google chooses to end their webp images with these and other webpage developers can do what ever they want.
-rw
-rw-no
-rwa
Does anyone know if ALL webp image urls will end in one of these 3 possibilities?
Maybe just Google chooses to end their webp images with these and other webpage developers can do what ever they want.
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
Re: Gui support for webp image format
Does this mean that an Autohotkey Gui can not support webp until Windows 10 has built in support for webp ?
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
Re: Gui support for webp image format
There is a libwebp dll that can decode webp to a hbitmap, then you can use Gui, Add, Picture,, HBITMAP:%handle%. But I'm not good at dllcalls..
There is also a command line tool dwebp.exe, that can decode webp to png file: https://developers.google.com/speed/webp/download
There is also a command line tool dwebp.exe, that can decode webp to png file: https://developers.google.com/speed/webp/download
Re: Gui support for webp image format
Using a .NET wrapper Imazen.WebP:
Code: Select all
; #Include, CLR.ahk ;https://www.autohotkey.com/boards/viewtopic.php?t=4633
#NoEnv
SetWorkingDir %A_ScriptDir%
if (A_PtrSize = 8)
DllCall("SetDllDirectory", "str", "libwebp.x64")
hBitmap := Webp_FileToHbitmap("test.webp")
; hBitmap := Webp_URLToHbitmap("https://www.gstatic.com/webp/gallery/1.webp")
Gui, Add, Pic, , HBITMAP:%hBitmap%
Gui, Show
DllCall("DeleteObject", "Ptr", hBitmap)
Return
GuiClose:
ExitApp
Webp_URLToHbitmap(URL) {
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("GET", URL, true)
whr.Send()
whr.WaitForResponse()
asm := Clr_LoadLibrary("Imazen.WebP.dll")
SimpleDecoder := asm.CreateInstance("Imazen.WebP.SimpleDecoder")
bitmap := SimpleDecoder.DecodeFromBytes(whr.responseBody, whr.responseBody.MaxIndex()+1)
return bitmap.GetHbitmap()
}
Webp_FileToHbitmap(WebpFile) {
bytes := File_To_SafeArray(WebpFile)
asm := Clr_LoadLibrary("Imazen.WebP.dll")
SimpleDecoder := asm.CreateInstance("Imazen.WebP.SimpleDecoder")
bitmap := SimpleDecoder.DecodeFromBytes(bytes, bytes.MaxIndex()+1)
return bitmap.GetHbitmap()
}
File_To_SafeArray(FileName) {
f := FileOpen(FileName, "r")
safeArr := ComObjArray(0x11, f.length) ; Create SAFEARRAY = VT_ARRAY|VT_UI1
pvData := NumGet(ComObjValue(safeArr) + 12 + (A_PtrSize==8 ? 4 : 0)) ; get pvData memeber
f.RawRead(pvData + 0, f.length) ; read raw data
f.Close()
return safeArr
}
- Attachments
-
- DisplayWebp.7z
- (329.34 KiB) Downloaded 183 times
-
- Posts: 4309
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Gui support for webp image format
@tmplinshi, interesting!
Managed to decode webp without external ahk-libraries:
Managed to decode webp without external ahk-libraries:
Code: Select all
webpUrl := "https://upload.wikimedia.org/wikipedia/commons/b/b2/Vulphere_WebP_OTAGROOVE_demonstration_2.webp"
libwebp32Url := "https://s3.amazonaws.com/resizer-dynamic-downloads/webp/0.5.2/x86/libwebp.dll"
libwebp64Url := "https://s3.amazonaws.com/resizer-dynamic-downloads/webp/0.5.2/x86_64/libwebp.dll"
filePath := A_ScriptDir . "\test.webp"
bitness := A_PtrSize*8
lib := A_ScriptDir . "\libwebp" . bitness . ".dll"
if !FileExist(filePath)
URLDownloadToFile, % webpUrl, % filePath
if !FileExist(lib)
URLDownloadToFile, % libwebp%bitness%Url, % lib
hBitmap := HBitmapFromWebP(lib, filePath, width, height)
Gui, Margin, 0, 0
Gui, Add, Pic, w600 h-1, HBITMAP:%hBitmap%
Gui, Show
Return
GuiClose() {
ExitApp
}
HBitmapFromWebP(libwebp, WebpFilePath, ByRef width, ByRef height) {
file := FileOpen(WebpFilePath, "r")
len := file.RawRead(buff, file.Length)
file.Close()
if !len
throw Exception("Failed to read the image file")
if !hLib := DllCall("LoadLibrary", Str, libwebp, Ptr)
throw Exception("Failed to load library. Error:" . A_LastError)
if !pBits := DllCall(libwebp . "\WebPDecodeRGBA", Ptr, &buff, Ptr, len, IntP, width, IntP, height) {
DllCall("FreeLibrary", Ptr, hLib)
throw Exception("Failed to decode the image file")
}
oGDIp := new GDIp
pBitmap := oGDIp.CreateBitmapFromScan0(width, height, pBits)
hBitmap := oGDIp.CreateHBITMAPFromBitmap(pBitmap)
DllCall(libwebp . "\WebPFree", Ptr, pBits)
oGDIp.DisposeImage(pBitmap)
DllCall("FreeLibrary", Ptr, hLib)
Return hBitmap
}
class GDIp {
__New() {
if !DllCall("GetModuleHandle", Str, "gdiplus", Ptr)
DllCall("LoadLibrary", Str, "gdiplus")
VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
DllCall("gdiplus\GdiplusStartup", UPtrP, pToken, Ptr, &si, Ptr, 0)
this.token := pToken
}
__Delete() {
DllCall("gdiplus\GdiplusShutdown", Ptr, this.token)
if hModule := DllCall("GetModuleHandle", Str, "gdiplus", Ptr)
DllCall("FreeLibrary", Ptr, hModule)
}
CreateBitmapFromScan0(Width, Height, pBits, PixelFormat := 0x26200A, Stride := "") {
if !Stride {
bpp := (PixelFormat & 0xFF00) >> 8
Stride := ((Width * bpp + 31) & ~31) >> 3
}
DllCall("gdiplus\GdipCreateBitmapFromScan0", Int, Width, Int, Height
, Int, Stride, Int, PixelFormat
, Ptr, pBits, PtrP, pBitmap)
Return pBitmap
}
CreateHBITMAPFromBitmap(pBitmap, Background=0xffffffff) {
DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", Ptr, pBitmap, PtrP, hbm, Int, Background)
return hbm
}
DisposeImage(pBitmap) {
return DllCall("gdiplus\GdipDisposeImage", Ptr, pBitmap)
}
}
Last edited by teadrinker on 19 Jul 2019, 17:26, edited 1 time in total.
Re: Gui support for webp image format
@teadrinker Awesome! Thanks a lot.
Re: Gui support for webp image format
All these examples look great but I can not use them.
I distribute my ahk file and prefer not to download dwebp.exe or Dll's to someone else's computer.
I prefer my scripts run properly "out of the box".
I do not want to require the end user to download libraries, dll's, functions and external programs.
If I can not include it in my .ahk file then I prefer not to use it.
I remember when I was a newbie I would attempt to run someone else's code and I would get "Call to nonexistent function". I would go find that function then that particular message would go away and I would get it again referring to a different function. It was very frustrating.
I may have to settle on my ahk script to not support webp image formats as far as it goes with displaying it on a gui.
thanks for all the suggestions. They are interesting.
I distribute my ahk file and prefer not to download dwebp.exe or Dll's to someone else's computer.
I prefer my scripts run properly "out of the box".
I do not want to require the end user to download libraries, dll's, functions and external programs.
If I can not include it in my .ahk file then I prefer not to use it.
I remember when I was a newbie I would attempt to run someone else's code and I would get "Call to nonexistent function". I would go find that function then that particular message would go away and I would get it again referring to a different function. It was very frustrating.
I may have to settle on my ahk script to not support webp image formats as far as it goes with displaying it on a gui.
thanks for all the suggestions. They are interesting.
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
Re: Gui support for webp image format
hmm, so you distribute one single ahk file? Why not distribute a zip containing the ahk file and dll file?
-
- Posts: 4309
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Gui support for webp image format Topic is solved
Just for fun, the code in attachment (since it is too large) will work without any dll and libraries at all.
- Attachments
-
- DecodeWebP.ahk
- (1.13 MiB) Downloaded 235 times
Re: Gui support for webp image format
libwebp dll is under the MIT license, which is very liberal. A person can do pretty much whatever, including commercially, as long as they give credit and include what is under the MIT license.
dwebp.exe appears to be under the Apache License 2.0. Though this license is a bit more convoluted than the MIT license, it allows personal and commercial use. However, you must also make sure to indicate what is under the Apache License.
While I totally understand that you want an all AHK solution, just saying that as 3rd party tools go, these permissive licenses will usually not cause trouble under most circumstances, even in a business or commercial setting.
Re: Gui support for webp image format
This works as expected. Now I can display webp image formats in an Autohotkey Gui with an all AHK solution.teadrinker wrote: ↑19 Jul 2019, 01:00Just for fun, the code in attachment (since it is too large) will work without any dll and libraries at all.
thank you very much
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
Re: Gui support for webp image format
This script is great. However, I think the colours are not coming out right e.g. blue instead of red.
Anyway, really nice script, thanks so much teadrinker and tmplinshi.
(Btw I've noticed a lot more webp files on the Internet very recently.)
Anyway, really nice script, thanks so much teadrinker and tmplinshi.
(Btw I've noticed a lot more webp files on the Internet very recently.)
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
-
- Posts: 4309
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Gui support for webp image format
Ha ha! You are right.
I mixed up WebPDecodeBGRA and WebPDecodeRGBA, now it's fixed.
Code: Select all
webpUrl := "https://upload.wikimedia.org/wikipedia/commons/b/b2/Vulphere_WebP_OTAGROOVE_demonstration_2.webp"
libwebp32Url := "https://s3.amazonaws.com/resizer-dynamic-downloads/webp/0.5.2/x86/libwebp.dll"
libwebp64Url := "https://s3.amazonaws.com/resizer-dynamic-downloads/webp/0.5.2/x86_64/libwebp.dll"
filePath := A_ScriptDir . "\test.webp"
bitness := A_PtrSize*8
lib := A_ScriptDir . "\libwebp" . bitness . ".dll"
if !FileExist(filePath)
URLDownloadToFile, % webpUrl, % filePath
if !FileExist(lib)
URLDownloadToFile, % libwebp%bitness%Url, % lib
hBitmap := HBitmapFromWebP(lib, filePath, width, height)
Gui, Margin, 0, 0
Gui, Add, Pic, w600 h-1, HBITMAP:%hBitmap%
Gui, Show
Return
GuiClose() {
ExitApp
}
HBitmapFromWebP(libwebp, WebpFilePath, ByRef width, ByRef height) {
file := FileOpen(WebpFilePath, "r")
len := file.RawRead(buff, file.Length)
file.Close()
if !len
throw Exception("Failed to read the image file")
if !hLib := DllCall("LoadLibrary", Str, libwebp, Ptr)
throw Exception("Failed to load library. Error:" . A_LastError)
if !pBits := DllCall(libwebp . "\WebPDecodeBGRA", Ptr, &buff, Ptr, len, IntP, width, IntP, height) {
DllCall("FreeLibrary", Ptr, hLib)
throw Exception("Failed to decode the image file")
}
oGDIp := new GDIp
pBitmap := oGDIp.CreateBitmapFromScan0(width, height, pBits)
hBitmap := oGDIp.CreateHBITMAPFromBitmap(pBitmap)
DllCall(libwebp . "\WebPFree", Ptr, pBits)
oGDIp.DisposeImage(pBitmap)
DllCall("FreeLibrary", Ptr, hLib)
Return hBitmap
}
class GDIp {
__New() {
if !DllCall("GetModuleHandle", Str, "gdiplus", Ptr)
DllCall("LoadLibrary", Str, "gdiplus")
VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
DllCall("gdiplus\GdiplusStartup", UPtrP, pToken, Ptr, &si, Ptr, 0)
this.token := pToken
}
__Delete() {
DllCall("gdiplus\GdiplusShutdown", Ptr, this.token)
if hModule := DllCall("GetModuleHandle", Str, "gdiplus", Ptr)
DllCall("FreeLibrary", Ptr, hModule)
}
CreateBitmapFromScan0(Width, Height, pBits, PixelFormat := 0x26200A, Stride := "") {
if !Stride {
bpp := (PixelFormat & 0xFF00) >> 8
Stride := ((Width * bpp + 31) & ~31) >> 3
}
DllCall("gdiplus\GdipCreateBitmapFromScan0", Int, Width, Int, Height
, Int, Stride, Int, PixelFormat
, Ptr, pBits, PtrP, pBitmap)
Return pBitmap
}
CreateHBITMAPFromBitmap(pBitmap, Background=0xffffffff) {
DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", Ptr, pBitmap, PtrP, hbm, Int, Background)
return hbm
}
DisposeImage(pBitmap) {
return DllCall("gdiplus\GdipDisposeImage", Ptr, pBitmap)
}
}
- Attachments
-
- DecodeWebP_AllInOne.ahk
- (1.13 MiB) Downloaded 244 times
Re: Gui support for webp image format
Good work teadrinker!
-
- Posts: 4309
- Joined: 29 Mar 2015, 09:41
- Contact:
Who is online
Users browsing this forum: FanaticGuru, Google [Bot], Jaroz and 131 guests