Skip to content

Commit

Permalink
Use LZW compression for tifs exported from atlas / composer
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Sep 18, 2017
1 parent 938f261 commit 90378b7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -76,6 +76,7 @@
#include <QFileDialog> #include <QFileDialog>
#include <QFileInfo> #include <QFileInfo>
#include <QIcon> #include <QIcon>
#include <QImageWriter>
#include <QLabel> #include <QLabel>
#include <QMatrix> #include <QMatrix>
#include <QMenuBar> #include <QMenuBar>
Expand Down Expand Up @@ -2069,7 +2070,7 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
outputFilePath = fi.absolutePath() + '/' + fi.baseName() + '_' + QString::number( i + 1 ) + '.' + fi.suffix(); outputFilePath = fi.absolutePath() + '/' + fi.baseName() + '_' + QString::number( i + 1 ) + '.' + fi.suffix();
} }


saveOk = image.save( outputFilePath, fileNExt.second.toLocal8Bit().constData() ); saveOk = saveImage( image, outputFilePath, fileNExt.second );


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


bool saveOk = image.save( imageFilename, format.toLocal8Bit().constData() ); bool saveOk = saveImage( image, imageFilename, format );
if ( !saveOk ) if ( !saveOk )
{ {
QMessageBox::warning( this, tr( "Atlas processing error" ), QMessageBox::warning( this, tr( "Atlas processing error" ),
Expand Down Expand Up @@ -2311,6 +2312,16 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
} }
} }


bool QgsComposer::saveImage( const QImage &img, const QString &imageFilename, const QString &imageFormat )
{
QImageWriter w( imageFilename, imageFormat.toLocal8Bit().constData() );
if ( imageFormat.compare( "tiff", Qt::CaseInsensitive ) == 0 || imageFormat.compare( "tif", Qt::CaseInsensitive ) == 0 )
{
w.setCompression( 1 ); //use LZW compression
}
return w.write( img );
}

void QgsComposer::on_mActionExportAtlasAsSVG_triggered() void QgsComposer::on_mActionExportAtlasAsSVG_triggered()
{ {
QgsComposition::AtlasMode previousMode = mComposition->atlasMode(); QgsComposition::AtlasMode previousMode = mComposition->atlasMode();
Expand Down
7 changes: 7 additions & 0 deletions src/app/composer/qgscomposer.h
Expand Up @@ -484,6 +484,13 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase


QgsPanelWidget *createItemWidget( QgsComposerItem *item ); QgsPanelWidget *createItemWidget( QgsComposerItem *item );


/*Saves image to file, possibly using format specific options (e.g. LZW compression for tiff)
@param img the image to save
@param imageFileName output file path
@param imageFormat format string
@param return true in case of success*/
static bool saveImage( const QImage &img, const QString &imageFilename, const QString &imageFormat );

QgsAppComposerInterface *mInterface = nullptr; QgsAppComposerInterface *mInterface = nullptr;


//! Labels in status bar which shows current mouse position //! Labels in status bar which shows current mouse position
Expand Down

0 comments on commit 90378b7

Please sign in to comment.