public async Task CycleTimeAsync(int framesPerHour = 1, int delay = 150, int?loop = null) { string path = $"../tmp/{Context.User.Id}_time.gif"; FontFace font = JsonHandler.Load <FontFace>(@"../assets/fonts/orikos.json"); char[][][][] charMap = JsonHandler.Load <char[][][][]>(@"../assets/char_map.json", new JsonCharArrayConverter()); var config = TextFactoryConfig.Default; config.CharMap = charMap; var frames = new List <Stream>(); var properties = new ImageProperties { TrimEmptyPixels = true, Padding = new Padding(2), Width = 47 }; float t = 0.00f; using (var factory = new TextFactory(config)) { factory.SetFont(font); for (float h = 0; h < 24 * framesPerHour; h++) { GammaPalette colors = TimeCycle.FromHour(t); properties.Matte = colors[Gamma.Min]; frames.Add(DrawFrame(factory, t.ToString("00.00H"), colors[Gamma.Max], properties)); t += (1.00f / framesPerHour); } } var gifStream = new MemoryStream(); using (var encoder = new GifEncoder(gifStream, repeatCount: loop)) { encoder.FrameLength = TimeSpan.FromMilliseconds(delay); foreach (Stream frame in frames) { await using (frame) encoder.EncodeFrame(Image.FromStream(frame)); } } gifStream.Position = 0; Image gifResult = Image.FromStream(gifStream); gifResult.Save(path, ImageFormat.Gif); await gifStream.DisposeAsync(); await Context.Channel.SendFileAsync(path); }
public async Task GetTimeAsync(float hour) { if (hour > 23.00f || hour < 0.00f) { await Context.Channel.SendMessageAsync("hour out of range"); return; } try { string path = $"../tmp/{Context.User.Id}_time.png"; var font = JsonHandler.Load <FontFace>(@"../assets/fonts/orikos.json"); // new OutlineProperties(1, new OriColor(0x44B29B)): Too taxing on performance as of now char[][][][] charMap = JsonHandler.Load <char[][][][]>(@"../assets/char_map.json", new JsonCharArrayConverter()); GammaPalette colors = TimeCycle.FromHour(hour); var config = TextFactoryConfig.Default; config.CharMap = charMap; var properties = new ImageProperties { TrimEmptyPixels = true, Padding = new Padding(2), Matte = colors[Gamma.Min] }; using (var factory = new TextFactory(config)) using (Bitmap bmp = factory.DrawText(hour.ToString("00.00H").ToUpper(), font, properties)) ImageHelper.Save(bmp, path, ImageFormat.Png); await Context.Channel.SendFileAsync(path); } catch (Exception ex) { await Context.Channel.CatchAsync(ex); } }