| 1 | #include "cover_utils.h" |
| 2 | |
| 3 | bool YACReader::saveCover(const QString &path, const QImage &cover) |
| 4 | { |
| 5 | QImage scaled; |
| 6 | if (cover.width() > cover.height()) { |
| 7 | scaled = cover.scaledToWidth(640, Qt::SmoothTransformation); |
| 8 | } else { |
| 9 | auto aspectRatio = static_cast<double>(cover.width()) / static_cast<double>(cover.height()); |
| 10 | auto maxAllowedAspectRatio = 0.5; |
| 11 | if (aspectRatio < maxAllowedAspectRatio) { // cover is too tall, e.g. webtoon |
| 12 | scaled = cover.scaledToHeight(960, Qt::SmoothTransformation); |
| 13 | } else { |
| 14 | scaled = cover.scaledToWidth(480, Qt::SmoothTransformation); |
| 15 | } |
| 16 | } |
| 17 | return scaled.save(path, 0, 75); |
| 18 | } |