Fix finding thumbnail size for /img-master/ images
https://pixwhile.zangetsu.kaizoku.cyou/artworks/115861083 https://pixwhile.zangetsu.kaizoku.cyou/artworks/116018582 https://pixwhile.zangetsu.kaizoku.cyou/artworks/84869687
This commit is contained in:
parent
e6f17d4b47
commit
6071c4720d
|
@ -308,21 +308,45 @@ static std::optional<std::pair<uint64_t, uint64_t>> get_thumbnail_size(blankie::
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t thumbnail_width, thumbnail_height;
|
||||||
|
|
||||||
|
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;
|
std::smatch sm;
|
||||||
if (!std::regex_match(thumbnail_url.path, sm, illust_size_regex)) {
|
if (!std::regex_match(thumbnail_url.path, sm, illust_size_regex)) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t thumbnail_width = to_ull(sm.str(1));
|
thumbnail_width = to_ull(sm.str(1));
|
||||||
// uint64_t thumbnail_height = to_ull(sm.str(2));
|
// 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)
|
// derived from original_size->second / (original_size->first / thumbnail_width)
|
||||||
// to make it more accurate without using floats
|
// to make it more accurate without using floats
|
||||||
original_size->second * thumbnail_width / original_size->first
|
thumbnail_height = original_size->second * thumbnail_width / original_size->first;
|
||||||
};
|
}
|
||||||
return real_thumbnail_size;
|
|
||||||
|
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) {
|
static Images get_illust_images(const nlohmann::json& image, std::optional<nlohmann::json> image_metadata) {
|
||||||
|
|
Loading…
Reference in New Issue