From 08740aec621a296497c8ed168672d62c3aad663e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 30 Apr 2021 23:03:47 +0200 Subject: Remove temporary file created for .webp thumbnails --- src/AsyncImageLoader.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/AsyncImageLoader.cpp') diff --git a/src/AsyncImageLoader.cpp b/src/AsyncImageLoader.cpp index 6504992..947f637 100644 --- a/src/AsyncImageLoader.cpp +++ b/src/AsyncImageLoader.cpp @@ -15,8 +15,9 @@ namespace QuickMedia { // TODO: Remove this when imagemagick supports webp // Convert webp to png + bool remove_tmp_input = false; if(content_type == ContentType::IMAGE_WEBP) { - Path result_path_tmp = input_path; + Path result_path_tmp = thumbnail_path_resized; result_path_tmp.append(".tmp.png"); const char *args[] = { "ffmpeg", "-y", "-v", "quiet", "-i", input_path.data.c_str(), "--", result_path_tmp.data.c_str(), nullptr}; @@ -25,13 +26,14 @@ namespace QuickMedia { return false; input_path = std::move(result_path_tmp); + remove_tmp_input = true; } // > is to only shrink image if smaller than the target size std::string new_size = std::to_string(resize_target_size.x) + "x" + std::to_string(resize_target_size.y) + ">"; // We only want the first frame if its a gif - Path thumbnail_path_first_frame = std::move(input_path); + Path thumbnail_path_first_frame = input_path; thumbnail_path_first_frame.append("[0]"); Path result_path_tmp = thumbnail_path_resized; @@ -39,6 +41,8 @@ namespace QuickMedia { const char *args[] = { "convert", thumbnail_path_first_frame.data.c_str(), "-thumbnail", new_size.c_str(), result_path_tmp.data.c_str(), nullptr}; int convert_res = exec_program(args, nullptr, nullptr); + if(remove_tmp_input) + remove(input_path.data.c_str()); if(convert_res == 0 && rename_atomic(result_path_tmp.data.c_str(), thumbnail_path_resized.data.c_str()) == 0) return true; else -- cgit v1.2.3