diff --git a/Library/Helpers/godotgif_loader.gd b/Library/Helpers/godotgif_loader.gd new file mode 100644 index 0000000..c6999bb --- /dev/null +++ b/Library/Helpers/godotgif_loader.gd @@ -0,0 +1,21 @@ +@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 diff --git a/Library/Helpers/godotgif_loader.gd.uid b/Library/Helpers/godotgif_loader.gd.uid new file mode 100644 index 0000000..b5278a8 --- /dev/null +++ b/Library/Helpers/godotgif_loader.gd.uid @@ -0,0 +1 @@ +uid://cor04lg8wc05p