summaryrefslogtreecommitdiff
path: root/src/addons/GifMaker/godot-gdgifexporter/README.md
blob: 8da7779db9ed75b2c58cae0934c9bcbd7e58cd9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Gif exporter for Godot made entirely in GDScript
This is gif exporter for godot made entirely using GDScript. This is based on [godot-gifexporter](https://github.com/novhack/godot-gifexporter).

<p align="center">
	<a href="https://github.com/godotengine/awesome-godot">
		<img src="https://awesome.re/mentioned-badge.svg" alt="Mentioned in Awesome Godot" />
	</a>
</p>

## Example
```gdscript
extends Node2D


# load gif exporter module
const GIFExporter = preload("res://gdgifexporter/exporter.gd")
# load quantization module that you want to use
const MedianCutQuantization = preload("res://gdgifexporter/quantization/median_cut.gd")


func _ready():
	var img := Image.new()
	# load your image from png file
	img.load('res://image.png')
	# remember to use this image format when exporting
	img.convert(Image.FORMAT_RGBA8)

	# initialize exporter object with width and height of gif canvas
	var exporter = GIFExporter.new(img1.get_width(), img1.get_height())
	# write image using median cut quantization method and with one second animation delay
	exporter.add_frame(img, 1, MedianCutQuantization)

	# when you have exported all frames of animation you, then you can save data into file
	var file: File = File.new()
	# open new file with write privlige
	file.open('user://result.gif', File.WRITE)
	# save data stream into file
	file.store_buffer(exporter.export_file_data())
	# close the file
	file.close()
```

## Quantization methods
Addon supports two quantization methods:
- Median Cut
- Uniform (with small color adjustment)

Both method files are stored in gdgifexporter/quantization directory.

## Error Codes
Some methods give error codes. These are used error codes and their meaning:
- OK = 0 (Everything went okay)
- EMPTY_IMAGE = 1 (Passed image object has no data in it)
- BAD_IMAGE_FORMAT = 2 (You are using different image format than FORMAT_RGBA8)

# Contributors
If you want to contribute to this code then go ahead! :) Huge thanks to Kinwailo and novhack. This project wouldn't work without their help! :D

# Used external libs
- [godot-gif-lzw](https://github.com/jegor377/godot-gif-lzw)