blankie 2024-02-20 23:05:44 +11:00
parent e6f17d4b47
commit 6071c4720d
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 35 additions and 11 deletions

View File

@ -308,21 +308,45 @@ static std::optional<std::pair<uint64_t, uint64_t>> get_thumbnail_size(blankie::
return std::nullopt;
}
std::smatch sm;
if (!std::regex_match(thumbnail_url.path, sm, illust_size_regex)) {
return std::nullopt;
}
uint64_t thumbnail_width, thumbnail_height;
uint64_t thumbnail_width = to_ull(sm.str(1));
// uint64_t thumbnail_height = to_ull(sm.str(2));
if (thumbnail_url.path.starts_with("/img-master/")) {
if (original_size->first <= 1200 && original_size->second <= 1200) {
return original_size;
}
// one side is implicitly 1200
if (original_size->first >= original_size->second) {
// original width >= original height
thumbnail_width = 1200;
// derived from original_size->second / (original_size->first / thumbnail_width)
// to make it more accurate without using floats
thumbnail_height = original_size->second * thumbnail_width / original_size->first;
} else {
// original width < original height
thumbnail_height = 1200;
// derived from original_size->first / (original_size->second / thumbnail_height)
// to make it more accurate without using floats
thumbnail_width = original_size->first * thumbnail_height / original_size->second;
}
} else {
std::smatch sm;
if (!std::regex_match(thumbnail_url.path, sm, illust_size_regex)) {
return std::nullopt;
}
thumbnail_width = to_ull(sm.str(1));
// thumbnail_height = to_ull(sm.str(2));
std::pair<uint64_t, uint64_t> real_thumbnail_size = {
thumbnail_width,
// derived from original_size->second / (original_size->first / thumbnail_width)
// to make it more accurate without using floats
original_size->second * thumbnail_width / original_size->first
};
return real_thumbnail_size;
thumbnail_height = original_size->second * thumbnail_width / original_size->first;
}
std::pair<uint64_t, uint64_t> thumbnail_size = {thumbnail_width, thumbnail_height};
return thumbnail_size;
}
static Images get_illust_images(const nlohmann::json& image, std::optional<nlohmann::json> image_metadata) {