[Qgis-user] How to control image exporter size (with QSize)

afernandez afernandez at odyhpc.com
Sun Feb 25 07:48:51 PST 2024


Hello,
I'm using the image exporter to create PNG files. Everything looks good but 
the files must have a resolution of 1,200 pixels in the horizontal 
direction. The snippet to create the image file reads:
exporter = QgsLayoutExporter(layout)
png_name = '/home/ubuntu/output/testing.png'
exporter.exportToImage(png_name, QgsLayoutExporter.ImageExportSettings())
The created file has a resolution of 3507 by 2480 pixels (not sure where 
these figures come from but QGIS seems to always use them).
When I modify the snippet with 
exporter = QgsLayoutExporter(layout)
canvas_settings = exporter.ImageExportSettings()
canvas_settings.dpi = 100
png_name = '/home/ubuntu/output/testing.png'
exporter.exportToImage(png_name, settings=canvas_settings)
The new file has a resolution of 1169x826 pixels (which is not very far 
from what I need). However, and when I try a tighter control with:
exporter = QgsLayoutExporter(layout)
canvas_settings = exporter.ImageExportSettings()
canvas_settings.imageSize = QSize(1200,750)
png_name = '/home/ubuntu/output/testing.png'
exporter.exportToImage(png_name, settings=canvas_settings)
it just seems to ignore QSize and reverts back to a 3507x2480 resolution. 
I'm not sure how achieve a finer control over the output. Thanks.
P.S. QGIS is v3.34 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20240225/671d7467/attachment.htm>


More information about the QGIS-User mailing list