Recent

Author Topic: [SOLVED] WebP images and BGRABitmap  (Read 2320 times)

AsleyCruz

  • Full Member
  • ***
  • Posts: 115
    • Graphic and web designer
[SOLVED] WebP images and BGRABitmap
« on: April 20, 2025, 08:08:05 am »
Hi bros, I would like to convert img.webp to img.png
but the below code does not work.

Please, help me to make this work properly, but using BGRABitmap to resize
the final image with resample function.

Thanks in advance.

Code: Pascal  [Select][+][-]
  1. uses
  2.   BGRAReadWebP, BGRABitmap;
  3.  
  4. //------------------------------------------------------
  5.  
  6. Image  := TFPMemoryImage.Create(10, 10);
  7. webPRead := TBGRAReaderWebP.Create;
  8. WriterPNG := TFPWriterPNG.Create;
  9.  
  10. Image.LoadFromFile('img.webp', webPRead);
  11. Image.SaveToFile('img.png', WriterPNG);
  12.  
  13. Image.free;
  14. webPRead.free;
  15. WriterPNG.free;
« Last Edit: April 21, 2025, 04:55:25 am by AsleyCruz »
Graphic & web designer

paweld

  • Hero Member
  • *****
  • Posts: 1375
Re: WebP images and BGRABitmap
« Reply #1 on: April 20, 2025, 08:20:35 am »
Code: Pascal  [Select][+][-]
  1. uses
  2.   BGRABitmap, BGRABitmapTypes, BGRAWriteWebP;
  3.  
  4. procedure TForm1.FormCreate(Sender: TObject);
  5. var
  6.   img: TBGRABitmap;
  7.   webpw: TBGRAWriterWebP;
  8.   new_width, new_height: Integer;
  9. begin
  10.   webpw := TBGRAWriterWebP.Create;
  11.   webpw.QualityPercent := 75;
  12.   img := TBGRABitmap.Create('myimage.png');
  13.   BGRAReplace(img, img.Resample(new_width, new_height, rmFineResample));
  14.   img.SaveToFile('myimage.webp', webpw);
  15.   FreeAndNil(webpw);
  16.   FreeAndNil(img);
  17. end;  
Best regards / Pozdrawiam
paweld

AsleyCruz

  • Full Member
  • ***
  • Posts: 115
    • Graphic and web designer
Re: WebP images and BGRABitmap
« Reply #2 on: April 20, 2025, 08:36:19 am »
...

Thanks for your help, paweld, but your code does not work :/
Please, check it out because the myimage.webp generated has 0 bytes.

And your code is to convert from .png to .webp
and my question is to convert from .webp to .png haha but both code would be useful.

Thanks again.
Graphic & web designer

paweld

  • Hero Member
  • *****
  • Posts: 1375
Re: WebP images and BGRABitmap
« Reply #3 on: April 20, 2025, 09:43:16 am »
It works, only you have to assign some values to the variables new_width and new_height.

And the conversion in the other direction below:
Code: Pascal  [Select][+][-]
  1. uses
  2.   BGRABitmap, BGRABitmapTypes, BGRAWritePNG;
  3.  
  4. procedure TForm1.FormCreate(Sender: TObject);
  5. img: TBGRABitmap;
  6.   pngw: TBGRAWriterPNG;
  7.   new_width, new_height: Integer;
  8. begin
  9.   new_width := 300;
  10.   new_height := 300;
  11.   pngw := TBGRAWriterPNG.Create;
  12.   img := TBGRABitmap.Create('myimage.webp');
  13.   BGRAReplace(img, img.Resample(new_width, new_height, rmFineResample));
  14.   img.SaveToFile('myimage1.png', pngw);
  15.   FreeAndNil(pngw);
  16.   FreeAndNil(img);
  17. end;
Best regards / Pozdrawiam
paweld

AsleyCruz

  • Full Member
  • ***
  • Posts: 115
    • Graphic and web designer
Re: WebP images and BGRABitmap
« Reply #4 on: April 20, 2025, 02:18:21 pm »
It works, only you have to assign some values to the variables new_width and new_height.

Sorry but got this error: Cannot find libwebp library (libwebp32.dll).

1. I have the dll files (libwebp32.dll and libwebp64.dll) in the save .exe folder and did not work
2. then copied the files to windows System32 folder and did not work.
3. and last tried to rename the dll files to "libwebp.dll" and did not work.

Any solution? Thanks a lot.
Graphic & web designer

AsleyCruz

  • Full Member
  • ***
  • Posts: 115
    • Graphic and web designer
Re: WebP images and BGRABitmap
« Reply #5 on: April 20, 2025, 03:51:13 pm »
Hi @lainz, maybe you (or someone else) can help me providing a final solution for this post.
Thanks in advance.

Graphic & web designer

rca

  • Full Member
  • ***
  • Posts: 102
Re: WebP images and BGRABitmap
« Reply #6 on: April 20, 2025, 05:30:15 pm »
Hi @AsleyCruz,

I've tested @paweld's latest code on Windows x64 and it works fine.

I downloaded the library from:
https://github.com/bgrabitmap/webp/blob/master/bgrawebp/libwebp64.dll

And a sample image "1.webp"
https://www.gstatic.com/webp/gallery/1.webp

I've attached the full project, including the library, the image, and @paweld's code.

AsleyCruz

  • Full Member
  • ***
  • Posts: 115
    • Graphic and web designer
Re: WebP images and BGRABitmap
« Reply #7 on: April 21, 2025, 02:25:01 am »
Hi @AsleyCruz,

I've tested @paweld's latest code on Windows x64 and it works fine.

Hi @rca, I have Windows 10 x64, Lazarus 3.4, latest version of BGRABitmap
and downloaded your sample and did NOT work :/

I don't know what is happening, tried all methods and nothing!
Thanks for your time.

Take a look at the animated gif.
Graphic & web designer

TRon

  • Hero Member
  • *****
  • Posts: 4371
Re: WebP images and BGRABitmap
« Reply #8 on: April 21, 2025, 02:40:45 am »
I don't know what is happening, tried all methods and nothing!
Therefor I have to assume you have checked if all (same bitness) dependencies are in place as well ? (e.g. this library does not seem it has every dependency statically linked in).
Today is tomorrow's yesterday.

rca

  • Full Member
  • ***
  • Posts: 102
Re: WebP images and BGRABitmap
« Reply #9 on: April 21, 2025, 03:36:46 am »
@AsleyCruz,

Try downloading the 32-bit library (libwebp32.dll) from
https://github.com/bgrabitmap/webp/blob/master/bgrawebp/libwebp32.dll

Replace the library you already had.
And check the size of libwebp32.dll:
384KB (393.216 bytes)

AsleyCruz

  • Full Member
  • ***
  • Posts: 115
    • Graphic and web designer
Re: WebP images and BGRABitmap
« Reply #10 on: April 21, 2025, 04:55:05 am »
@rca @paweld

I found the solution and I share with you in case someone else get this error.
The zip file contains x86 and x64 dll and copy the dll to your application folder.

The dll file (vcruntime140.dll) was missing, but now is working perfectly.

Thanks again!
Graphic & web designer

TRon

  • Hero Member
  • *****
  • Posts: 4371
Re: WebP images and BGRABitmap
« Reply #11 on: April 21, 2025, 05:25:05 am »
The dll file (vcruntime140.dll) was missing, but now is working perfectly.
:shrugs:
Today is tomorrow's yesterday.

circular

  • Hero Member
  • *****
  • Posts: 4417
    • Personal webpage
Re: [SOLVED] WebP images and BGRABitmap
« Reply #12 on: April 21, 2025, 07:36:38 pm »
That's good to know. Thanks AsleyCruz for sharing the solution. I suppose this dependency did not appear previously because it is already on some systems or only required by the 32-bit version of the DLL. I'm thinking of adding it in the folder with libwebp binaries for Windows, however it has the same name for the 32-bit and 64-bit version.

Binaries folder: https://github.com/bgrabitmap/bgrabitmap/tree/dev-bgrabitmap/libwebp
Conscience is the debugger of the mind

AsleyCruz

  • Full Member
  • ***
  • Posts: 115
    • Graphic and web designer
Re: [SOLVED] WebP images and BGRABitmap
« Reply #13 on: April 21, 2025, 11:58:19 pm »
That's good to know. Thanks AsleyCruz for sharing the solution.

Hi @circular, I downloaded the dll files (vcruntime140.dll x86 & x64) from the below link:
https://www.dll-files.com/vcruntime140.dll.html

I was able to reproduce this bug because I always test my little applications on a virtual Windows 7 & 10
without any .Net Framework library installed.

Regards.
Graphic & web designer

lainz

  • Hero Member
  • *****
  • Posts: 4713
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: [SOLVED] WebP images and BGRABitmap
« Reply #14 on: April 22, 2025, 12:30:36 am »
That's not net is visual c++. Vcredist is the installer you need to run on your pc to install the missing files.

Windows 7 is outdated also Windows 10.. You should test on Windows 11.

 

TinyPortal © 2005-2018