Recent

Author Topic: [SOLVED] Libwebp  (Read 665 times)

pcurtis

  • Sr. Member
  • ****
  • Posts: 483
[SOLVED] Libwebp
« 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.
« Last Edit: December 10, 2020, 10:09:09 am by pcurtis »
Windows 10 / Linux Mint 20
Laz 2.0.12
FPC 3.2.0

circular

  • Hero Member
  • *****
  • Posts: 3679
    • Personal webpage
Re: Libwebp
« Reply #1 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.
Conscience is the debugger of the mind

pcurtis

  • Sr. Member
  • ****
  • Posts: 483
Re: Libwebp
« Reply #2 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
Windows 10 / Linux Mint 20
Laz 2.0.12
FPC 3.2.0

circular

  • Hero Member
  • *****
  • Posts: 3679
    • Personal webpage
Re: Libwebp
« Reply #3 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.
Conscience is the debugger of the mind

pcurtis

  • Sr. Member
  • ****
  • Posts: 483
Re: Libwebp
« Reply #4 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;
Windows 10 / Linux Mint 20
Laz 2.0.12
FPC 3.2.0

 

TinyPortal © 2005-2018