1 /**
2  * Image module.
3  *
4  * License:
5  *     MIT. See LICENSE for full details.
6  */
7 module tkd.image.gif;
8 
9 /**
10  * Imports.
11  */
12 import std.base64;
13 import std.file;
14 import tkd.image.image;
15 import tkd.image.imageformat;
16 
17 /**
18  * Helper class to quickly create an embedded Gif format image.
19  *
20  * See_Also:
21  *     $(LINK2 ../image/image.html, tkd.image.image) $(BR)
22  */
23 class Gif : Image
24 {
25 	/**
26 	 * Construct the image.
27 	 *
28 	 * Params:
29 	 *     file = The file name of the image to load.
30 	 */
31 	public this(string file)
32 	{
33 		super();
34 
35 		this.setFormat(ImageFormat.gif);
36 
37 		if (file)
38 		{
39 			this.setFile(file);
40 		}
41 	}
42 
43 	/**
44 	 * Select the index if a multi-indexed gif.
45 	 * If you select an idex which doesn't exist in the image an error will occur.
46 	 *
47 	 * Params:
48 	 *     index = The index to select.
49 	 *
50 	 * Returns:
51 	 *     This image to aid method chaining.
52 	 */
53 	public auto setIndex(this T)(int index)
54 	{
55 		this._tk.eval("%s configure -format {gif -index %s}", this.id, index);
56 
57 		return cast(T) this;
58 	}
59 }
60 
61 /**
62  * Helper class to quickly create an embedded Gif format image.
63  *
64  * Params:
65  *     file = The file name of the image to embed.
66  *
67  * See_Also:
68  *     $(LINK2 ../image/image.html, tkd.image.image) $(BR)
69  */
70 class EmbeddedGif(string file) : Gif
71 {
72 	/**
73 	 * Construct the image.
74 	 */
75 	public this()
76 	{
77 		super(null);
78 
79 		this.embedBase64Data!(file);
80 	}
81 }