Skip to content

Commit 90378b7

Browse files
committed
Use LZW compression for tifs exported from atlas / composer
1 parent 938f261 commit 90378b7

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/app/composer/qgscomposer.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
#include <QFileDialog>
7777
#include <QFileInfo>
7878
#include <QIcon>
79+
#include <QImageWriter>
7980
#include <QLabel>
8081
#include <QMatrix>
8182
#include <QMenuBar>
@@ -2069,7 +2070,7 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
20692070
outputFilePath = fi.absolutePath() + '/' + fi.baseName() + '_' + QString::number( i + 1 ) + '.' + fi.suffix();
20702071
}
20712072

2072-
saveOk = image.save( outputFilePath, fileNExt.second.toLocal8Bit().constData() );
2073+
saveOk = saveImage( image, outputFilePath, fileNExt.second );
20732074

20742075
if ( !saveOk )
20752076
{
@@ -2269,7 +2270,7 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
22692270
imageFilename = fi.absolutePath() + '/' + fi.baseName() + '_' + QString::number( i + 1 ) + '.' + fi.suffix();
22702271
}
22712272

2272-
bool saveOk = image.save( imageFilename, format.toLocal8Bit().constData() );
2273+
bool saveOk = saveImage( image, imageFilename, format );
22732274
if ( !saveOk )
22742275
{
22752276
QMessageBox::warning( this, tr( "Atlas processing error" ),
@@ -2311,6 +2312,16 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
23112312
}
23122313
}
23132314

2315+
bool QgsComposer::saveImage( const QImage &img, const QString &imageFilename, const QString &imageFormat )
2316+
{
2317+
QImageWriter w( imageFilename, imageFormat.toLocal8Bit().constData() );
2318+
if ( imageFormat.compare( "tiff", Qt::CaseInsensitive ) == 0 || imageFormat.compare( "tif", Qt::CaseInsensitive ) == 0 )
2319+
{
2320+
w.setCompression( 1 ); //use LZW compression
2321+
}
2322+
return w.write( img );
2323+
}
2324+
23142325
void QgsComposer::on_mActionExportAtlasAsSVG_triggered()
23152326
{
23162327
QgsComposition::AtlasMode previousMode = mComposition->atlasMode();

src/app/composer/qgscomposer.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,13 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
484484

485485
QgsPanelWidget *createItemWidget( QgsComposerItem *item );
486486

487+
/*Saves image to file, possibly using format specific options (e.g. LZW compression for tiff)
488+
@param img the image to save
489+
@param imageFileName output file path
490+
@param imageFormat format string
491+
@param return true in case of success*/
492+
static bool saveImage( const QImage &img, const QString &imageFilename, const QString &imageFormat );
493+
487494
QgsAppComposerInterface *mInterface = nullptr;
488495

489496
//! Labels in status bar which shows current mouse position

0 commit comments

Comments
 (0)