Skip to content
Permalink
Browse files

Warning when image ratio prevents export

  • Loading branch information
m-kuhn committed Mar 22, 2021
1 parent 75c1f78 commit 6f361a75988d74ee05062ca5745f0a21e8856ee4
Showing with 4 additions and 2 deletions.
  1. +4 −2 src/core/layout/qgslayoutexporter.cpp
@@ -199,12 +199,14 @@ QImage QgsLayoutExporter::renderPageToImage( int page, QSize imageSize, double d

QRectF paperRect = QRectF( pageItem->pos().x(), pageItem->pos().y(), pageItem->rect().width(), pageItem->rect().height() );

if ( imageSize.isValid() && ( !qgsDoubleNear( static_cast< double >( imageSize.width() ) / imageSize.height(),
paperRect.width() / paperRect.height(), 0.008 ) ) )
const double imageAspectRatio = static_cast< double >( imageSize.width() ) / imageSize.height();
const double paperAspectRatio = paperRect.width() / paperRect.height();
if ( imageSize.isValid() && ( !qgsDoubleNear( imageAspectRatio, paperAspectRatio, 0.008 ) ) )
{
// specified image size is wrong aspect ratio for paper rect - so ignore it and just use dpi
// this can happen e.g. as a result of data defined page sizes
// see https://github.com/qgis/QGIS/issues/26422
QgsMessageLog::logMessage( QObject::tr( "Ignoring custom image size because aspect ratio %1 does not match paper ratio %2" ).arg( QString::number( imageAspectRatio, 'g', 3 ), QString::number( paperAspectRatio, 'g', 3 ) ), QStringLiteral( "Layout" ), Qgis::Warning );
imageSize = QSize();
}

0 comments on commit 6f361a7

Please sign in to comment.