B4J Question WebP images and B4J, is it possible to convert jpg to webp ?

Magma

Expert
Licensed User
Longtime User
Hi there...

last days i was testing webp images and i have to say they are very good !

B4J has a library here... that can help load them as a simple image...

But is it possible to convert bytes or image of jpeg for example ---> to bytes of webp and how (with source code at b4j) ?

ps: Some will tell - why you didn't just change the quality of jpeg...
image.WriteToStream(out, quality, "JPEG")
but what i want is something like this:
image.WriteToStream(out, quality, "WEBP")
but there is not an option for webp :-(
 
Last edited:

MarcoRome

Expert
Licensed User
Longtime User
Look this:
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
actually getting this when i try to convert a jpg file to webp:

 
Upvote 0

Magma

Expert
Licensed User
Longtime User
Upvote 0

Magma

Expert
Licensed User
Longtime User
If someone get into this thread will read my monologue

Searching all over ther internet..


Found this: https://github.com/zakgof/webp4j and hey... remember that Erel wrapped this library...

scrolling down the page and i ve seen what i ve been looking...

B4X:
// Encode
BufferedImage bi = ...
float quality = 80f;
byte[] bytes = Webp4j.encode(bi, quality);

// Decode
BufferedImage restored = Webp4j.decode(bytes);

but hey in B4J Library WebP... there is only Load from file... not encode/decode :-( . ... is there a way with JavaObject or inline java someway ?
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
Never tried it but you can probably use ffmpeg (calling it from jShell) using a command like this:
B4X:
ffmpeg -i file.webp out.png
or
ffmpeg -i file.webp out.jpg
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
Need the reverse

image.WriteToStream(out, quality, "WEBP")

Will be better to have them in bytes without messing files... And without the need of ffmpeg

I will check the webp B4xlib and try to extend it with encode as Erel said to me .. hope i ll have time on weekend
 
Upvote 0

Quandalle

Member
Licensed User
Here is an example of conversion using cwebp.exe the webp image compressor developed by Google

B4X:
Public Sub jpeg2webp(dir As String ,fn As String)
    Dim shl As Shell
    ' call convert doing resize 
    Dim fullpath As String = File.Combine(dir,fn)
    shl.Initialize("shl", File.DirApp &"\cwebp.exe", Array As String("-resize","0","750",fullpath, "-o",fullpath.SubString2(0,fullpath.Length-4) & "webp"))
    shl.WorkingDirectory = File.dirapp
    shl.Run(-1)
    wait for shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    If Not(Success) Then
        Log(StdErr )
    End If
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…