diff --git a/Program.fs b/Program.fs index ee9b6fa..d51c64a 100644 --- a/Program.fs +++ b/Program.fs @@ -9,17 +9,15 @@ type options = { [] recursive: bool } -let getFrameFromGif (path: string) : byte[] = - let gif = Image.Load(path) - let frame = gif.Frames.RootFrame - use image = new Image(frame.Width, frame.Height) - let source = frame :?> ImageFrame - for y in 0..frame.Height-1 do - for x in 0..frame.Width-1 do - image.[x,y] <- source.[x,y] - use ms = new MemoryStream() +let getFrameFromGif (path: string) = + use gif = Image.Load(path) + use image = new Image(gif.Width, gif.Height) + image.Frames.AddFrame(gif.Frames.RootFrame)|> ignore + image.Frames.RemoveFrame(0) + let ms = new MemoryStream() image.SaveAsPng(ms) - ms.ToArray() + ms.Seek(0L, SeekOrigin.Begin) |> ignore + ms let processFiles options : Unit = match Directory.Exists options.directory with @@ -29,11 +27,12 @@ let processFiles options : Unit = let progress = AnsiConsole.Status() let processEachFile (ctx:StatusContext) = for path in files do - let bytes = getFrameFromGif path let filename = Path.GetFileNameWithoutExtension path let target = $"%s{filename}.png" + use destinationStream = File.Create target + use frameStream = getFrameFromGif path AnsiConsole.MarkupLine $"[green]:check_mark: Processing %s{Path.GetFileName path} -> %s{target}[/]" - File.WriteAllBytes(target, bytes) + frameStream.CopyTo(destinationStream) progress.Start($"processing {files.Length} GIFs", processEachFile) AnsiConsole.MarkupLine($"[green]:glowing_star: { files.Length} GIFs processed in {options.directory}[/]") | false -> diff --git a/readme.md b/readme.md index 73cbf60..99c5e7d 100644 --- a/readme.md +++ b/readme.md @@ -28,7 +28,7 @@ Copyright (C) 2021 FreezeFrame ## Licenses For ImageSharp -- This tool uses [ImageSharp](https://sixlabors.com/products/imagesharp/), which requires a license for commercial use. +- This tool uses [ImageSharp](https://sixlabors.com/products/imagesharp/), which requires a license for commercial support. ## License @@ -39,4 +39,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.