Page 1 of 1
Image Plugin for Webp format
Posted: Sat Jun 18, 2022 11:47 pm
by IdeasVacuum
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
Re: Image Plugin for Webp format
Posted: Tue Jun 21, 2022 7:49 pm
by Seymour Clufley
+1
Definitely. This format is everywhere now.
Re: Image Plugin for Webp format
Posted: Mon Nov 21, 2022 10:34 pm
by DeanH
+1
High priority please!
In the meantime, does anyone know of a freeware dll that can load this format?
Re: Image Plugin for Webp format
Posted: Tue Nov 22, 2022 1:12 pm
by Caronte3D
+1
Re: Image Plugin for Webp format
Posted: Tue Nov 22, 2022 1:28 pm
by jacdelad
+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).
Re: Image Plugin for Webp format
Posted: Tue Nov 22, 2022 10:19 pm
by BarryG
DeanH wrote: Mon Nov 21, 2022 10:34 pmIn the meantime, does anyone know of a freeware dll that can load this format?
The FreeImage Project does (it's a DLL) ->
https://freeimage.sourceforge.io/
But see this post ->
viewtopic.php?p=576176#p576176
Re: Image Plugin for Webp format
Posted: Wed Nov 23, 2022 5:37 am
by jacdelad
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.
Re: Image Plugin for Webp format
Posted: Fri May 12, 2023 1:10 pm
by Seymour Clufley
WebP support is really becoming a glaring omission at this point.
Re: Image Plugin for Webp format
Posted: Fri May 12, 2023 1:32 pm
by User23
+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)
Re: Image Plugin for Webp format
Posted: Sun May 14, 2023 10:53 am
by Seymour Clufley
User23 wrote: Fri May 12, 2023 1:32 pm
+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)
Thanks for that suggestion. Good idea for the meantime.
Re: Image Plugin for Webp format
Posted: Thu May 18, 2023 11:17 am
by Seymour Clufley
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
Re: Image Plugin for Webp format
Posted: Mon May 22, 2023 4:46 am
by DeanH
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?
Re: Image Plugin for Webp format
Posted: Tue May 23, 2023 3:56 am
by DeanH
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.
Re: Image Plugin for Webp format
Posted: Fri Jan 10, 2025 10:02 am
by Marc56us
+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).

Re: Image Plugin for Webp format
Posted: Fri Jan 10, 2025 12:31 pm
by le_magn
+1