Image Plugin for Webp format
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Image Plugin for Webp format
Pure Basic is handy for automating the creation of HTML files. However, the Webp format is becoming very popular (High Quality, small file size) but PB does not support it.
https://developers.google.com/speed/webp
Encoders are available for Windows, Linux and macOS:
https://developers.google.com/speed/web ... recompiled
https://developers.google.com/speed/web ... iling#unix
https://developers.google.com/speed/webp
Encoders are available for Windows, Linux and macOS:
https://developers.google.com/speed/web ... recompiled
https://developers.google.com/speed/web ... iling#unix
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
-
- Addict
- Posts: 1265
- Joined: Wed Feb 28, 2007 9:13 am
- Location: London
Re: Image Plugin for Webp format
+1
Definitely. This format is everywhere now.
Definitely. This format is everywhere now.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
- DeanH
- Enthusiast
- Posts: 278
- Joined: Wed May 07, 2008 4:57 am
- Location: Adelaide, South Australia
- Contact:
Re: Image Plugin for Webp format
+1
High priority please!
In the meantime, does anyone know of a freeware dll that can load this format?
High priority please!
In the meantime, does anyone know of a freeware dll that can load this format?
Re: Image Plugin for Webp format
+1 and I would pay a few bucks. (Also I'd like to see JPEGXL, which also has cross platform libraries and will cause a heated debate if I ask for it).
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Re: Image Plugin for Webp format
The FreeImage Project does (it's a DLL) -> https://freeimage.sourceforge.io/DeanH wrote: Mon Nov 21, 2022 10:34 pmIn the meantime, does anyone know of a freeware dll that can load this format?
But see this post -> viewtopic.php?p=576176#p576176
Re: Image Plugin for Webp format
Thank Barry, I know, but I couldn't find code how to use it (and my attempts didn't work for now, also maybe someone will share it so there would be no need to reinvent the wheel).
Edit: Following your post I saw there maybe already is come code available. Thanks. The power of this library seems to be limitless, there's a lot to do.
Edit: Following your post I saw there maybe already is come code available. Thanks. The power of this library seems to be limitless, there's a lot to do.
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
-
- Addict
- Posts: 1265
- Joined: Wed Feb 28, 2007 9:13 am
- Location: London
Re: Image Plugin for Webp format
WebP support is really becoming a glaring omission at this point.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
Re: Image Plugin for Webp format
+1
In the meantime, I use dwebp with RunProgram to transform the image to PNG.
Only 460 ko but then because I need JPG, I have to do then a LoadImage/SaveImage to go from PNG to JPG so load two plugins as well (PNGdecoder/ JPGEncoder)
In the meantime, I use dwebp with RunProgram to transform the image to PNG.
Only 460 ko but then because I need JPG, I have to do then a LoadImage/SaveImage to go from PNG to JPG so load two plugins as well (PNGdecoder/ JPGEncoder)
-
- Addict
- Posts: 1265
- Joined: Wed Feb 28, 2007 9:13 am
- Location: London
Re: Image Plugin for Webp format
Thanks for that suggestion. Good idea for the meantime.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
-
- Addict
- Posts: 1265
- Joined: Wed Feb 28, 2007 9:13 am
- Location: London
Re: Image Plugin for Webp format
Here is code for loading and saving WebP images in the meantime, using LibWebP. You just need to change the first line to point to the LibWebP bin folder.
Code: Select all
#LibWebpDirectory = "P:\libwebp-1.3.0-windows-x64\libwebp-1.3.0-windows-x64\bin\"
Global c34.s{1} = Chr(34)
#DwebpExe = #LibWebpDirectory+"dwebp.exe"
Procedure.i LoadWebpImageUsingTempFile(webp_fn.s)
folder.s = GetTemporaryDirectory()
png_fn.s = folder+Str(Random(9999999,1000000))+".png"
param.s = c34+webp_fn+c34+" -o "+c34+png_fn+c34
RunProgram(#DwebpExe,param,folder,#PB_Program_Wait)
UsePNGImageDecoder()
img.i = LoadImage(#PB_Any,png_fn)
ProcedureReturn img
EndProcedure
Procedure.i LoadWebpImage(webp_fn.s)
param.s = c34+webp_fn+c34+" -o -"
prog.i = RunProgram(#DwebpExe,param,GetPathPart(webp_fn),#PB_Program_Open | #PB_Program_Error | #PB_Program_Read)
memsize.i = 0
While ProgramRunning(prog)
temp_memsize.i = AvailableProgramOutput(prog)
If temp_memsize
memsize = temp_memsize
;Debug "avo: "+Str(memsize)
*mem = ReAllocateMemory(*mem,memsize)
ReadProgramData(prog,*mem,memsize)
EndIf
er.s = ReadProgramError(prog)
If er="Saved to stdout"
;Debug "err: "+er
Break
EndIf
Wend
CloseProgram(prog)
UsePNGImageDecoder()
img.i = CatchImage(#PB_Any,*mem,memsize)
ProcedureReturn img
EndProcedure
#CwebpExe = #LibWebpDirectory+"cwebp.exe"
Procedure.b SaveWebpImage(img.i,webp_fn.s)
folder.s = GetTemporaryDirectory()
png_fn.s = folder+Str(Random(9999999,1000000))+".png"
UsePNGImageEncoder()
SaveImage(img,png_fn,#PB_ImagePlugin_PNG)
param.s = c34+png_fn+c34+" -o "+c34+webp_fn+c34
prog.i = RunProgram(#CwebpExe,param,GetPathPart(webp_fn),#PB_Program_Open | #PB_Program_Error | #PB_Program_Read)
While ProgramRunning(prog)
st.s = ReadProgramString(prog)
If st<>""
Debug "str: "+st
EndIf
er.s = ReadProgramError(prog)
If er<>""
Debug "err: "+er
EndIf
Wend
CloseProgram(prog)
DeleteFile(png_fn)
ProcedureReturn #True
EndProcedure
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
- DeanH
- Enthusiast
- Posts: 278
- Joined: Wed May 07, 2008 4:57 am
- Location: Adelaide, South Australia
- Contact:
Re: Image Plugin for Webp format
Seymour that is really useful! I was able to get it to work with my folder arrangement. Now have to work out whether I want it to change format when a user saves a .webp file or do it on the fly when displaying. Probably the former. It would be better if it was a dll instead of an exe, and am wondering why the developers didn't produce that. Or have I missed it?
- DeanH
- Enthusiast
- Posts: 278
- Joined: Wed May 07, 2008 4:57 am
- Location: Adelaide, South Australia
- Contact:
Re: Image Plugin for Webp format
I have found a webp image file that LoadWebpImage does not load, at least on my laptop here at work. It seems to go through the steps but *mem and memsize are both 0. No error is reported. Other webp images I have tried do load successfully.
The image file is at http://bookmark.central.sa.edu.au/1865154954.webp
It displays in Chrome, Firefox and Edge browsers.
The image file is at http://bookmark.central.sa.edu.au/1865154954.webp
It displays in Chrome, Firefox and Edge browsers.
Re: Image Plugin for Webp format
+1 also, at least for a decoder, as this format is becoming more and more common.
The encoder is less important (IMHO), given that this format is not as extraordinary as it is presented (a JPG whose default compression factor is increased gives fairly close results for current uses).

The encoder is less important (IMHO), given that this format is not as extraordinary as it is presented (a JPG whose default compression factor is increased gives fairly close results for current uses).
