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 GraphicsService() { _text = new TextFactory(GetDefaultCharMap()); _text.SetFont(GetFont(FontType.Orikos)); Palette = GetPalette(PaletteType.Default); }