Lazarus

Programming => Graphics and Multimedia => Graphics => Topic started by: pcurtis on December 09, 2020, 10:49:14 am

Title: [SOLVED] Libwebp
Post by: pcurtis on December 09, 2020, 10:49:14 am
Hi All,

How can I use libwebp64.dll (standalone) in my app to convert a jpg to webp?

Thanks in advance.
Title: Re: Libwebp
Post by: circular on December 09, 2020, 03:44:40 pm
BGRABitmap provides a reader/writer that uses this library. See BGRAReadWebP and BGRAWriteWebp units.

You can as well use directly libwebp.pas unit from the package.
Title: Re: Libwebp
Post by: pcurtis on December 09, 2020, 04:04:31 pm
OK Thanks. Any chance of a guideline how I can use it?

I just was to save / convert 'x' to a webp with a quality of say 75
Title: Re: Libwebp
Post by: circular on December 09, 2020, 05:52:56 pm
Basically, here is how to do:
- put the library in the same folder as your program (under Windows, on Linux the library is already installed)
- add BGRABitmap to your project
- write the code to convert

In the code, create a TBGRABitmap from unit BGRABitmap, do LoadFromFile with the source and SaveToFile with the destination. It will guess from extensions the file format.

If you want to specify parameters for the writer, you need to create a TBGRAWriterWebP from unit BGRAWriteWebP and set its properties and add it as an additional parameters to SaveToFile.
Title: Re: Libwebp
Post by: pcurtis on December 10, 2020, 10:08:25 am
Job done. Thanks.

I tried it with

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   MyImage : TBGRABitmap;
  4.   MyDetails : TBGRAWriterWebP;
  5. begin
  6.   MyDetails := TBGRAWriterWebP.Create;
  7.   MyDetails.QualityPercent := 75;
  8.   MyDetails.Lossless := false;
  9.  
  10.   MyImage := TBGRABitmap.Create;
  11.   MyImage.LoadFromFile('25606.jpg');
  12.   MyImage.SaveToFile('25606.webp', MyDetails);
  13.  
  14.   MyDetails.Free;
  15.   MyImage.Free;
  16. end;
TinyPortal © 2005-2018