Recent

Author Topic: Animated Gif and Animated Png from Image Folders: Can APNG be Optimized?  (Read 1435 times)

Boleeman

  • Hero Member
  • *****
  • Posts: 654
Upgraded to: Animated Gif and Animated Png from Image Folders (see later replies)

Was investigating how to make animated gifs from folders containing images (Png, Bmp, Gif, Jpg) for the Tween program.

Found a thread by my friend DreamVB (from the good old PlanetVb of years gone by) on this Lazarus Forum and I expanded on his Lazarus code.


Place numbered images in particular folders starting from .001

Uses TBgrabmp
Can change size, delay, Loopcount
Creates an output folder and lists percentage size in filename.


Might be nice to add a feature to split an animated gif back to say png files.

Anyhow, enjoy what I have been playing around with.

Attached is also an animated gif made from a folder containing pngs which has been incresed in size to 140 percent.

Greets to DreamVB.
« Last Edit: September 07, 2024, 12:56:38 am by Boleeman »

circular

  • Hero Member
  • *****
  • Posts: 4345
    • Personal webpage
Re: Animated Gif from Image Folders: Investigating
« Reply #1 on: September 02, 2024, 07:13:19 pm »
Nice project  :)

One remark, the OptimizeFrames method is supposed to be called after adding the frames. You will get smaller output files this way.
Conscience is the debugger of the mind

Fred vS

  • Hero Member
  • *****
  • Posts: 3313
    • StrumPract is the musicians best friend
Re: Animated Gif from Image Folders: Investigating
« Reply #2 on: September 02, 2024, 07:21:40 pm »
Very nice project!
Note that if you want to export to a open-source format (GIF is not open source  :'( ), you may use animated PNG (APNG): https://en.wikipedia.org/wiki/APNG
And, of course, BGRABitmap can deal perfectly with it.
« Last Edit: September 02, 2024, 07:30:36 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Boleeman

  • Hero Member
  • *****
  • Posts: 654
Re: Animated Gif from Image Folders: Investigating
« Reply #3 on: September 03, 2024, 09:48:22 am »
Thanks Circular for that OptimizeFrames method advice.
I was referencing different threads on animated gifs and was unsure of where to put actually put it.
While investigating, I noticed some animated gif sizes seemed a bit larger than I was expecting so I see now why the OptimizeFrames method is called after adding the frames.


Fred vS, thanks for your nice reply. I also wanted to look at APNG but was unaware that BGRABitmap can deal with it. The quality of the APNG animation looks amazing.

I teach Basic animation at a college and wanted to maybe make a basic animator using Lazarus, and do some Squash and Stretch like your ball bounce example. I used to use Pencil animator, but have switched to Wick (Vector) Animator. This is based on Javascript. It would be nice to see something similar done in Lazarus.
« Last Edit: September 03, 2024, 09:51:11 am by Boleeman »

Fred vS

  • Hero Member
  • *****
  • Posts: 3313
    • StrumPract is the musicians best friend
Re: Animated Gif from Image Folders: Investigating
« Reply #4 on: September 03, 2024, 02:52:45 pm »
Hello.
Yes APNG is great and can deal with transparency (Animated GIF cannot).
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Boleeman

  • Hero Member
  • *****
  • Posts: 654
Re: Animated Gif from Image Folders: Investigating
« Reply #5 on: September 03, 2024, 03:28:52 pm »
I wonder, is there any sample code that creates APNG in Lazarus ?

I know ImagingLib does it, but does TBgrabmp do it?

I am interested in trying it out.

Fred vS

  • Hero Member
  • *****
  • Posts: 3313
    • StrumPract is the musicians best friend
Re: Animated Gif from Image Folders: Investigating
« Reply #6 on: September 03, 2024, 03:39:55 pm »
I wonder, is there any sample code that creates APNG in Lazarus ?

I know ImagingLib does it, but does TBgrabmp do it?

I am interested in trying it out.

The demo testgif was updated to render apng.
https://github.com/bgrabitmap/bgrabitmap/tree/master/test/testgif

Note that I did not yet try to create a apng, only render it.
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Roland57

  • Sr. Member
  • ****
  • Posts: 450
    • msegui.net
Re: Animated Gif from Image Folders: Investigating
« Reply #7 on: September 04, 2024, 01:27:41 pm »
I didn't know APNG. Very interesting. I see it's possible to create APNG files with ImageMagick.
My projects are on Gitlab and on Codeberg.

Fred vS

  • Hero Member
  • *****
  • Posts: 3313
    • StrumPract is the musicians best friend
Re: Animated Gif from Image Folders: Investigating
« Reply #8 on: September 04, 2024, 02:50:41 pm »
I didn't know APNG. Very interesting. I see it's possible to create APNG files with ImageMagick.
Here some investigation-solution for rendering APNG with BGRABitmap: https://github.com/bgrabitmap/bgrabitmap/issues/105
Maybe BGRABitmap could be used to create APNG too.
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

circular

  • Hero Member
  • *****
  • Posts: 4345
    • Personal webpage
Re: Animated Gif from Image Folders: Investigating
« Reply #9 on: September 04, 2024, 04:41:51 pm »
Yes, you can create APNG files, using TBGRAAnimatedPng class, also in BGRAAnimatedGif unit.  :)
Conscience is the debugger of the mind

Fred vS

  • Hero Member
  • *****
  • Posts: 3313
    • StrumPract is the musicians best friend
Re: Animated Gif from Image Folders: Investigating
« Reply #10 on: September 04, 2024, 05:09:45 pm »
Yes, you can create APNG files, using TBGRAAnimatedPng class, also in BGRAAnimatedGif unit.  :)
Wow, BGRABitmap simply the best and the best simple.  ;D
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

circular

  • Hero Member
  • *****
  • Posts: 4345
    • Personal webpage
Re: Animated Gif from Image Folders: Investigating
« Reply #11 on: September 05, 2024, 02:31:36 pm »
Thanks. Yes, simplicity is my motto.  :)
Conscience is the debugger of the mind

Boleeman

  • Hero Member
  • *****
  • Posts: 654
Re: Animated Png and Gif from Image Folders: Found out how to do it
« Reply #12 on: September 06, 2024, 07:19:07 am »
Now saving to APNG as well as animated Gif

 Might be nice to add a display animated png/gif to this demo.

« Last Edit: September 06, 2024, 07:42:47 am by Boleeman »

Awkward

  • Full Member
  • ***
  • Posts: 138
Re: Animated Gif and Animated Png from Image Folders
« Reply #13 on: September 06, 2024, 07:46:05 am »
little offtoped. why you didn't check MNG for animation?

Boleeman

  • Hero Member
  • *****
  • Posts: 654
Re: Animated Gif and Animated Png from Image Folders
« Reply #14 on: September 06, 2024, 10:49:55 am »
Now showing the Animated Gif/Png using FredVs gbrabmp Testgif code.

Attached is a test animated png of my H-Fractal.
The animated png is smaller in size than the animated gif.

What I also noticed:

Decreasing the size of the animated gif or animated png from 100% increases the size of the animated file.

Not sure why this happens ?

I naturally assumed that initially setting a smaller percentage animated image size makes the output animated image size smaller.

Also test making an APNG with tweens, from my tween program.
« Last Edit: September 06, 2024, 01:08:40 pm by Boleeman »

 

TinyPortal © 2005-2018