From cd486a7040973673ab68e8f7f6e4d0c81225ef8e Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Fri, 3 May 2024 09:59:02 -0400 Subject: [PATCH] image: Support exporting GIF files --- Userland/Utilities/image.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Userland/Utilities/image.cpp b/Userland/Utilities/image.cpp index 1b2d54bed4b..f1bd4a79d75 100644 --- a/Userland/Utilities/image.cpp +++ b/Userland/Utilities/image.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -168,6 +169,10 @@ static ErrorOr save_image(LoadedImage& image, StringView out_path, bool pp auto& frame = image.bitmap.get>(); + if (out_path.ends_with(".gif"sv, CaseSensitivity::CaseInsensitive)) { + TRY(Gfx::GIFWriter::encode(*TRY(stream()), *frame)); + return {}; + } if (out_path.ends_with(".jpg"sv, CaseSensitivity::CaseInsensitive) || out_path.ends_with(".jpeg"sv, CaseSensitivity::CaseInsensitive)) { TRY(Gfx::JPEGWriter::encode(*TRY(stream()), *frame, { .icc_data = image.icc_data, .quality = jpeg_quality })); return {}; @@ -190,7 +195,7 @@ static ErrorOr save_image(LoadedImage& image, StringView out_path, bool pp } else if (out_path.ends_with(".qoi"sv, CaseSensitivity::CaseInsensitive)) { bytes = TRY(Gfx::QOIWriter::encode(*frame)); } else { - return Error::from_string_view("can only write .bmp, .jpg, .png, .ppm, .qoi, and .webp"sv); + return Error::from_string_view("can only write .bmp, .gif, .jpg, .png, .ppm, .qoi, and .webp"sv); } TRY(TRY(stream())->write_until_depleted(bytes));