diff --git a/YACReaderLibrary/initial_comic_info_extractor.cpp b/YACReaderLibrary/initial_comic_info_extractor.cpp index 08d8612e..f815a25a 100644 --- a/YACReaderLibrary/initial_comic_info_extractor.cpp +++ b/YACReaderLibrary/initial_comic_info_extractor.cpp @@ -72,14 +72,7 @@ void InitialComicInfoExtractor::extract() _cover = p; _coverSize = QPair(p.width(), p.height()); if (_target != "") { - QImage scaled; - if (p.width() > p.height()) // landscape?? - { - scaled = p.scaledToWidth(640, Qt::SmoothTransformation); - } else { - scaled = p.scaledToWidth(480, Qt::SmoothTransformation); - } - scaled.save(_target, 0, 75); + saveCover(_target, p); } else if (_target != "") { QLOG_WARN() << "Extracting cover: requested cover index greater than numPages " << _fileSource; // QImage p; @@ -151,14 +144,7 @@ void InitialComicInfoExtractor::extract() QImage p; if (p.loadFromData(archive.getRawDataAtIndex(index))) { _coverSize = QPair(p.width(), p.height()); - QImage scaled; - if (p.width() > p.height()) // landscape?? - { - scaled = p.scaledToWidth(640, Qt::SmoothTransformation); - } else { - scaled = p.scaledToWidth(480, Qt::SmoothTransformation); - } - scaled.save(_target, 0, 75); + saveCover(_target, p); } else { QLOG_WARN() << "Extracting cover: unable to load image from extracted cover " << _fileSource; // p.load(":/images/notCover.png"); @@ -172,3 +158,20 @@ QByteArray InitialComicInfoExtractor::getXMLInfoRawData() { return _xmlInfoData; } + +void InitialComicInfoExtractor::saveCover(const QString &path, const QImage &cover) +{ + QImage scaled; + if (cover.width() > cover.height()) { + scaled = cover.scaledToWidth(640, Qt::SmoothTransformation); + } else { + auto aspectRatio = static_cast(cover.width()) / static_cast(cover.height()); + auto maxAllowedAspectRatio = 0.5; + if (aspectRatio < maxAllowedAspectRatio) { // cover is too tall, e.g. webtoon + scaled = cover.scaledToHeight(960, Qt::SmoothTransformation); + } else { + scaled = cover.scaledToWidth(480, Qt::SmoothTransformation); + } + } + scaled.save(_target, 0, 75); +} diff --git a/YACReaderLibrary/initial_comic_info_extractor.h b/YACReaderLibrary/initial_comic_info_extractor.h index 34879da3..b59024b0 100644 --- a/YACReaderLibrary/initial_comic_info_extractor.h +++ b/YACReaderLibrary/initial_comic_info_extractor.h @@ -21,6 +21,7 @@ private: int _coverPage; static bool crash; QByteArray _xmlInfoData; + void saveCover(const QString &path, const QImage &cover); public slots: void extract();