Hammerspoon / hammerspoon

Staggeringly powerful macOS desktop automation with Lua
http://www.hammerspoon.org
MIT License
11.88k stars 578 forks source link

Add animated GIF support to hs.image #3280

Open latenitefilms opened 2 years ago

latenitefilms commented 2 years ago

My idea is that we could then use hs.canvas to manipulate the individual frames as hs.image objects.

I'm thinking:

--- hs.image.imagesFromGIF(path) -> table
--- Function
--- Creates a table of hs.image objects from an animated GIF.
---
--- Parameters:
---  * path - A path to an animated GIF
---
--- Returns:
---  * A table of hs.image objects per each frame in the GIF.

--- hs.image.imagesToGIF(path) -> boolean, string
--- Function
--- Saves an animated GIF to disk.
---
--- Parameters:
---  * path - A path to where you want to save the animated GIF.
---  * frameRate - Frames per second
---  * loop - A boolean which sets if the animated GIF should loop
---
--- Returns:
---  * `true` if successful otherwise `false`.
---  * An error message, if unsuccessful.

--- hs.image.imageFromVideo() -> imageObject, string
--- Constructor
--- Gets an individual frame as a still image from a video file.
---
--- Parameters:
---  * secondsNumerator - numerator as a number.
---  * secondsDenominator - denominator as a number.
---
--- Returns:
---  * An `hs.image` object or `nil`, if the video could not be processed.
---  * An error message, if unsuccessful.
---
--- Notes:
---  * The `secondsNumerator` and `secondsDenominator` make up a rational
---    number in of seconds with a 64-bit numerator and a 32-bit denominator.
---  * A numerator of 5 and a denominator of 1, would mean 5 seconds (5/1).

Is this a crazy idea @asmagill ?

asmagill commented 1 year ago

It's been a while since I looked at it, but there is some support in hs.canvas for displaying animated gifs... I remember I had to create a special class for it and to be able to select specific frames, so it might be a good place to start.

latenitefilms commented 9 months ago

I'm still interested in this. I'll try have a proper look over the Christmas break.