1 /**
2  * Image module.
3  *
4  * License:
5  *     MIT. See LICENSE for full details.
6  */
7 module tkd.image.png;
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 a Png format image.
19  *
20  * See_Also:
21  *     $(LINK2 ../image/image.html, tkd.image.image) $(BR)
22  */
23 class Png : 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.png);
36 
37 		if (file)
38 		{
39 			this.setFile(file);
40 		}
41 	}
42 
43 	/**
44 	 * Set the image alpha.
45 	 *
46 	 * Params:
47 	 *     alpha = The alpha of the image.
48 	 *
49 	 * Returns:
50 	 *     This image to aid method chaining.
51 	 */
52 	public auto setAlpha(this T)(double alpha)
53 	{
54 		if (alpha < 0f || alpha > 1.0f)
55 		{
56 			alpha = 1.0f;
57 		}
58 
59 		this._tk.eval("%s configure -format {png -alpha %s}", this.id, alpha);
60 
61 		return cast(T) this;
62 	}
63 }
64 
65 /**
66  * Helper class to quickly create an embedded Png format image.
67  *
68  * Params:
69  *     file = The file name of the image to embed.
70  *
71  * See_Also:
72  *     $(LINK2 ../image/image.html, tkd.image.image) $(BR)
73  */
74 class EmbeddedPng(string file) : Png
75 {
76 	/**
77 	 * Construct the image.
78 	 */
79 	public this()
80 	{
81 		super(null);
82 
83 		this.embedBase64Data!(file);
84 	}
85 }