From f5e6fce5c18dfaf165f76ad75d8a32698a4ab691 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Mon, 6 Nov 2023 19:56:27 +0900 Subject: [PATCH] gif: corrected the wrong aspect ratio scaling. --- src/bindings/wasm/tvgWasm.cpp | 6 +++++- src/tools/lottie2gif/lottie2gif.cpp | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/bindings/wasm/tvgWasm.cpp b/src/bindings/wasm/tvgWasm.cpp index a6b845b3..99c36508 100644 --- a/src/bindings/wasm/tvgWasm.cpp +++ b/src/bindings/wasm/tvgWasm.cpp @@ -230,7 +230,11 @@ public: return false; } - animation->picture()->size(width, height); + //keep the aspect ratio. + float ow, oh; + animation->picture()->size(&ow, &oh); + float scale = static_cast(width) / ow; + animation->picture()->size(ow * scale, oh * scale); auto saver = Saver::gen(); if (!saver) { diff --git a/src/tools/lottie2gif/lottie2gif.cpp b/src/tools/lottie2gif/lottie2gif.cpp index c880f191..ff213968 100644 --- a/src/tools/lottie2gif/lottie2gif.cpp +++ b/src/tools/lottie2gif/lottie2gif.cpp @@ -72,7 +72,10 @@ private: auto picture = animation->picture(); if (picture->load(in) != Result::Success) return false; - picture->size(static_cast(width), static_cast(height)); + float width, height; + picture->size(&width, &height); + float scale = static_cast(this->width) / width; + picture->size(width * scale, height * scale); auto saver = Saver::gen(); if (saver->save(std::move(animation), out, 100, fps) != Result::Success) return false;