pokepurple/Library/Helpers/godotgif_loader.gd
Mario Steele ee8d8bcc22 Add GodotGifLoader
Added GodotGifLoader, which uses the GodotGif GDExtension GIF Loader to load GIF files.
2025-06-13 02:44:25 -05:00

21 lines
729 B
GDScript

@icon("res://addons/twitcher/assets/media-loader-icon.svg")
@tool
extends NativeImageTransformer
## Godot Addon GIF parser written as GDExtension. Most of the time stable but there
## are GIF's that may not work cause the file didn't follow the GIF specification.
class_name GodotGifTransformer
func is_supported_animation() -> bool:
return true
func convert_image(path: String, buffer_in: PackedByteArray, output_path: String) -> SpriteFrames:
var tex: SpriteFrames
if buffer_in.size() > 0:
tex = GifManager.sprite_frames_from_buffer(buffer_in)
else:
tex = GifManager.sprite_frames_from_file(path)
ResourceSaver.save(tex, output_path, ResourceSaver.SaverFlags.FLAG_COMPRESS)
tex.take_over_path(path)
return tex