Skip to content

Safely probe GIFs for attributes including transparency

License

Notifications You must be signed in to change notification settings

Lantern-chat/gif_probe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gif_probe

Probes a GIF to detect if it actually has transparent pixels, and accumulates misc data while we're at it.

The final algorithm for this is lightweight and simple, and only requires reading the first frame in full.

For the common GIF, there are only two ways to obtain real transparency. It can either have transparent pixels in the first frame, or clears parts of the image using the Background dispose method after a frame. Technically, the Background dispose method is supposed to fill in the frame with the background color, but everyone ignores that.

Therefore, it is not necessary to actually accumulate and dispose pixels values.

Note: This binary intentionally has bad error handling. It either succeeds or it doesn't. Any file that fails to process should be considered invalid.

Usage:

gif_probe
    [-l max_duration_in_ms]
    [-d max_pixels]
    [-m max_memory_in_bytes]
     -i path/file.gif

Or pass -i - to read from stdin, which can be useful when spawning as a subprocess.

Example usage in PowerShell 7+:

# Using `gif_probe` directly:
gif_probe -i "path/file.gif"

# Using `Get-Content` to read the file as a byte stream. `-AsByteStream -Raw` is required.
Get-Content -Path "path/file.gif" -AsByteStream -Raw | gif_probe -i - | ConvertFrom-Json

Example output:

{
  "alpha": false,
  "max_colors": 256,
  "duration": 267,
  "frames": 40,
  "width": 480,
  "height": 270
}

About

Safely probe GIFs for attributes including transparency

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages