How to export 24-bit RGB PNG via scripting

I have a script that takes an already loaded GeoTIFF image and exports the image to PNG at certain bounds with a certain name. The clipping and naming works fine, but the output PNG is always 32-bit. How can I get the PNGs to be standard 24-bit RGB? The scripting reference documentation says that unless I'm explicitly writing out a paletted image, then it will default to 24-bit RGB. I'm determining the output PNGs to be 32-bit by the metadata dialog after loading them back into Global mapper. I'm doing this in GM12, though I have access to version 15. The EXPORT_RASTER line of the script is as follows:

EXPORT_RASTER TYPE="PNG" FILENAME="output\sat_N40d18m_W080d08m.png" PIXEL_SIZE="4335x4335" GLOBAL_BOUNDS="-80.13333333333334,40.3,-80.10000000000001,40.33333333333333" 

Best Answer

  • bmg_bobbmg_bob Global Mapper Programmer Posts: 2,180
    edited June 2016 Answer ✓
    ejk said:
    I tried both your and my script on a 2-week trial of Global Mapper 17 and it still outputs a 32-bit PNG as reported in the metadata. I guess to be clear, I'm loading an image into the UI and then going to File > Run Script to run the script. I'm not running globalmapper.exe from the command line. I'm not sure if that makes a difference.

    The image I load into the UI is a 3-band 24-bit GeoTIFF.
    That is exactly how I ran the script.  The only difference is that my original data was a 3-band, 24-bit SID file instead of a GeoTIFF.  I tried using a GeoTIFF, and still got the correct output.

    Have you tried adding the parameter "BG_TRANSPARENT=NO"?  By default, for PNG files, the value is YES (for other formats that use it, it defaults to NO) and signals the PNG exporter to add an alpha channel.

    Cheers,

    Bob

Answers

  • bmg_bobbmg_bob Global Mapper Programmer Posts: 2,180
    Hello,

    Using Global Mapper 17, I exported a 24-bit PNG file, and when I loaded it, the metadata says that it has 3 color bands, and a bit depth of 24.

    It is possible that there is a bug in the script export in version 12, or a bug in the metadata display.  Do you have another way to get information about the PNG file to determine whether it is 24 or 32 bits?

    Cheers,

    Bob
  • ejkejk Posts: 5
    edited June 2016
    If I use the regular GUI to export a PNG, then I do in fact get a 24-bit PNG. It seems to just be using the scripting method that returns a 32-bit PNG. I tried the script in Global Mapper 15 and it also gave me a 32-bit PNG.

    I confirmed the PNGs were 32-bit, 4-band with an Alpha channel using a gdal application in addition to the metadata display within Global Mapper.

    Did you use a GMS script to create the 24-bit PNG in Global Mapper 17?
  • bmg_bobbmg_bob Global Mapper Programmer Posts: 2,180
    ejk said:

    Did you use a GMS script to create the 24-bit PNG in Global Mapper 17?
    I used both the UI and a script.  My script command is pretty basic:
    EXPORT_RASTER TYPE="PNG" FILENAME="P:\Output\PNG\ScriptExport.png" GEN_PRJ_FILE=YES GEN_WORLD_FILE=YES
    Cheers,

    Bob
  • ejkejk Posts: 5
    I tried using your exact script text in Global Mapper 12 and 15 and still get a 32-bit PNG output. Was there a change made to PNG export between v15 and v17?

    But there is a GDAL application I can use to convert the outputs to 24-bit, so I may just try that.
  • bmg_bobbmg_bob Global Mapper Programmer Posts: 2,180
    ejk said:
    I tried using your exact script text in Global Mapper 12 and 15 and still get a 32-bit PNG output. Was there a change made to PNG export between v15 and v17?

    It appears that there was, given that the export works in Global Mapper 17 and not v12 or v15, but I don't have more details at the moment.

    You can test your script in the latest released version, if you would like to.  After installation, choose the option for a two-week trial on the Licensing screen.

    Cheers,

    Bob
  • ejkejk Posts: 5
    I tried both your and my script on a 2-week trial of Global Mapper 17 and it still outputs a 32-bit PNG as reported in the metadata. I guess to be clear, I'm loading an image into the UI and then going to File > Run Script to run the script. I'm not running globalmapper.exe from the command line. I'm not sure if that makes a difference.

    The image I load into the UI is a 3-band 24-bit GeoTIFF.
  • ejkejk Posts: 5
    Adding BG_TRANSPARENT="NO" seems to work and produce a 24-bit PNG, even in Global Mapper 12. I had thought about this parameter before but this line in the scripting reference documentation made me believe it was off by default:
    "BG_TRANSPARENT (ECW, GEOTIFF, JPEG2000 and PNG only) - specifies that any areas of no data/background should be marked as transparent. Use BG_TRANSPARENT=YES to enable."

    I interpreted that as, "this parameter only works for these 4 image types, and you have to set it to YES to turn it on, otherwise it's turned off." It might be helpful to update that line to be a little more clear about its default state.

    Thank you for sticking with this thread though, I think things are working now.
  • bmg_bobbmg_bob Global Mapper Programmer Posts: 2,180
    I am glad that you are getting your desired output.  The description of the BG_TRANSPARENT parameter is confusing with respect to PNG output.  I will see about updating it.

    Cheers,

    Bob
Sign In or Register to comment.