2

I am trying to export an image from QGIS with a transparent background, but it doesn't appear to be working. I have tried this in both version 3.22.15-LTR and also 3.28.3. I have tried following the directions in Exporting map with transparent background in QGIS

I find it hard to believe that there is a bug in QGIS (for this function). So I wonder if there is a setting in QGIS that I don't know about.

Steps:

  1. Create a new print layout
  2. Right-click, bring up "Page Properties" menu. Use slider to set Opacity to zero
  3. Click Add Item and Add a new map.
  4. Hover over the map, right click and bring up "Item Properties" menu. Uncheck background.
  5. Export image to TIFF. Verify that TIFF is a 32-bit TIFF file. Background pixels are definitely white.

I did this same procedure on a different computer a few days ago and it seemed to work. Most notably, when I used the slider to set opacity to zero (step 2), the background went from white to gray. When I try that I my current installation, it does not happen.

How can I address this problem?

P.S. Added in response to Babel

I double checked the output TIFF image and verified that it is a 4-byte RGB formatted image (TIFF tag 338, "Extra Samples", was set to 2 for Unassociated Alpha). So it seems that the white background is being added by the Print Layout.

5
  • TIFF format does not seem to support transparency, see: stackoverflow.com/a/48948606/13651925 Try saving in a format that supports transparency, like png
    – Babel
    Feb 4, 2023 at 21:16
  • Good idea, but unfortunately it didn't work. I tried exporting the image as a PNG, but it still had an opaque white background. So I suspect that there is some setting in QGIS that I just don't know about. As I said in my post, when I ran the program a few days ago, the white background for the page went away when I adjusted the slider. Running today, it persisted.
    – Gary Lucas
    Feb 4, 2023 at 23:56
  • I don't know what happened in your case -for me it works fine with 3.28.0 on Win10 to export transparent TIFF files. Did you really follow all the steps in the linked answer correctly? Can you post a screenshot showing your print composer: do you have a transparent background there (before exporting)? I suspect that probably you have not made all settings correctly, but from far, without a screenshot and without having your very project, it's difficult to say...
    – Babel
    Feb 5, 2023 at 10:58
  • By the way: why do you think that output tif is not transparent? Did you view it with an image software that can handly transparency? For me, opening the result with IrfanView, the background appears totally black, with MS Paint, it is completely white, but indeed the background is transparent (tested with another software that can handly layers and another image in the background). Just to make sure because you mentioned you were working on another machine. So maybe you can share the result for testing?
    – Babel
    Feb 5, 2023 at 11:05
  • 1
    I tried dragging the output image onto Google Earth. I also inspected it's content using a debugger and putting a breakpoint into the section of code that read the pixels from the file. Sure enough, all the background pixels had values 0xffffffff. After I saw you latest comment, I did some more poking around and found the problem, which I describe below. Thanks for pointing me in the right direction.
    – Gary Lucas
    Feb 5, 2023 at 13:49

1 Answer 1

1

I found the source of the problem. It was a combination of a minor operability issue and some bad luck.

When you invoke the Page Properties option on the Print Layout, QGIS presents the dialog below

enter image description here

The first thing I did when I saw it was to click on the triangle next to the background entry. That action raises a color-specification dialog which includes a slider for opacity. I set the opacity to zero. It turns out that that particular opacity setting does nothing. The color settings are propagated to the background, but the opacity is not. My bad luck was finding this color-setting dialog. My mistake was assuming that it was how the user was supposed to set the background opacity.

Most people would have clicked the bar to the left of the triangle. That action raises a different dialog that the following opacity setting. That is the one that the user is supposed to use.

enter image description here

Once I realized my mistake (which took an embarrassingly long time), QGIS worked like a champ.

2
  • You could also have used the Opacity slider visible on your second screenshot and set it to 0%
    – Babel
    Feb 5, 2023 at 13:52
  • 1
    Strange enough, when I click on the triangle and set transparent color there, it still exports a TIFF including transparence. Don't know what went wrong in your case. Great to see you problem solved, however!
    – Babel
    Feb 5, 2023 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.