How to export to PNG with transparent background

6136
8
Jump to solution
08-12-2013 10:38 PM
BenoitMetzger
New Contributor II
Hi there,

I used the following line of code to export an mxd to PNG 8 bit (i am creating tiles)... BUT i cant seem to set the background to transparent (or No Color)... any clue as to what parameter  i should use?!

arcpy.mapping.ExportToPNG(mxd, pngpath, df, df_export_width = 256, df_export_height = 256, resolution = 70, world_file=False, color_mode = "8-BIT_PALETTE", background_color = "No Color", transparent_color = "No Color")


I read on other forum threads that by setting the background color and transparent color to the same value should do the trick... it does not work in my case.

The data-frame background color is set to Hollow...


Any tips would be great 🙂
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
markdenil
Occasional Contributor III
Feature transparency support in image export has been on the wish list for a long time.
What you seem to want is, also, a partial transparence;
which is even more complicated, and even less likley to be avaliable soon.

You could try using a diagonal line fill over the areas you want partly transparent;
make the lines the color you will set as the transparent background color.
This "should" break up the opaque image into strips, with transparent strips between.

Obviously, the success of this illusion will be zoom dependant.
The trick is to get the line width and spacing right for the zoom you want to optimize.
Thus, you will still see the overlay tile and the underlying base map,
both with enough coherence to make them understandable.

...not, likely, a very good solution.

View solution in original post

0 Kudos
8 Replies
markdenil
Occasional Contributor III
Yes, set the background color and the transparant color to the same color.
However, "No Color" is not a color.

Try:
color_mode="24-BIT_TRUE_COLOR",
background_color="255,0,255",
transparent_color="255,0,255"

255 0 255 is magenta (also called minus blue).
Of course, if you are using magenta in the map you may want to pick a different color
or rethink your symbol colors... please 😉

If you really need 8 bit color, then you need to pick one of your palleted colors to sacrifice to transparancy.
0 Kudos
BenoitMetzger
New Contributor II
worked like a charm, thank you !
0 Kudos
BenoitMetzger
New Contributor II
Hi Mark,

Now that i have the background set as being fully transparent, I was wondering if it is possible to set some transparency to the rest of the PNG.

Basically, I am creating tile layers and would like to set a transparency to the tile so I can see through in case I have a basemap underneath. My layer in the mxd has a transparency set to 40% but when exported as an image, the PNG is not transparent...

Any help would be great.

Thanks in advance!

Ben
0 Kudos
markdenil
Occasional Contributor III
Feature transparency support in image export has been on the wish list for a long time.
What you seem to want is, also, a partial transparence;
which is even more complicated, and even less likley to be avaliable soon.

You could try using a diagonal line fill over the areas you want partly transparent;
make the lines the color you will set as the transparent background color.
This "should" break up the opaque image into strips, with transparent strips between.

Obviously, the success of this illusion will be zoom dependant.
The trick is to get the line width and spacing right for the zoom you want to optimize.
Thus, you will still see the overlay tile and the underlying base map,
both with enough coherence to make them understandable.

...not, likely, a very good solution.
0 Kudos
RhettZufelt
MVP Frequent Contributor
Ben,

Not sure on "tile" layers, but it sounds like you are putting this image into ArcMap (since you mention there may be a basemap underneath).

If so, you can get properties of the layer in the mxd, Display tab, there is a transperancy setting.

Othewise, you can set it with the layer properties http://resources.arcgis.com/en/help/main/10.1/index.html#//00s300000008000000 .

R_
0 Kudos
BenoitMetzger
New Contributor II
Thanks Mark and Rhett,

looks like it's a dead end for transparency on the layer then.

Rhett, you are right in the case where the tiles are viewed in ArcGIS. But it is not my case, I actually load these tiles in n SQLite database to be viewed on another platform (and that platform does not have transparency settings).

Setting transparency to the entire tile sadly seems not possible in ArcGIS... I managed to do this with Smallworld though...

Thanks again for your help.

Cheers.
0 Kudos
MattSayler
Occasional Contributor II
The PIL(Python Image Library) or Pillow (fork of PIL) modules might have a way. They're for working with several image formats in python. I haven't used either though. I just know of their existence.
0 Kudos
KarstenSedmera
New Contributor
Sorry for the cross-over in sites.  But I developed a Python-window script, posted here.

http://gis.stackexchange.com/questions/71973/how-to-export-a-mxd-to-a-image-with-transparent-backgro...
0 Kudos