Skip to main content
Participant
August 1, 2011
Answered

Saving an image as TGA with transparency

  • August 1, 2011
  • 5 replies
  • 60593 views

Hi, I wrote text and with a transparent background, how to I save as TGA....When i open up the tga file the background is white, not transparent.

When I save it as PNG transparency shows.

thanks

    This topic has been closed for replies.
    Correct answer Noel Carboni

    If I recall correctly, for TGA transparency you actually have to save the transparency as an Alpha channel yourself.

    Something along these lines:

    • Make sure you have no selection.
    • Right click on the mask that's giving your layer transparency.
    • Click "Add Mask to Selection".
    • Click the Select menu, choose "Save Selection...", and save it as a new alpha channel in your image, call it Transparency.
    • Make sure "Alpha channels" is checked when saving your image.

    This is purely from memory; I haven't time to test it.

    -Noel

    5 replies

    Participant
    February 9, 2023

    The answer appears to have become irrelevant in the last 12 years, anyone no how to do this in 2023? The option to select an alpha layer while trying to save as a .tga is greyed out. I'm lost.

    Jeff Arola
    Community Expert
    Community Expert
    February 9, 2023

    What version of photoshop and operating system are you using?

     

    Do you have any Alpha channels in the Channels panel?

    Participating Frequently
    June 11, 2023

    CC 24.5.0 I need to know how to do this as well

    Participant
    March 14, 2022

    This jsx script for save all visible in TGA, with transparency:

     

    #target photoshop
    
    
    
    cTID = function(s) { return app.charIDToTypeID(s); };
    sTID = function(s) { return app.stringIDToTypeID(s); };
    var doc = app.activeDocument;
    var filename = doc.name;
    var filepath = doc.path;
    filename = filename.slice(0, filename.lastIndexOf("."));
    var file = new File(filepath +"/" + filename + ".tga");
    //------------------------------------------- Duplicate file
    var duppedDocument = app.activeDocument.duplicate();
    app.activeDocument = duppedDocument;
    
    
    //-------- Выбираем видимый слой, иначе мердж не работает, и обьединяем видимое
    if (1 < duppedDocument.layers.length) {
    	for (var j = 0; j < duppedDocument.layers.length; j++) {
    		if (duppedDocument.layers[j].visible){
    			duppedDocument.activeLayer = duppedDocument.layers[j]
    			j = duppedDocument.layers.length;
    		  }
    		}
    	duppedDocument.mergeVisibleLayers();
    }
    
    makeAlpha_from_Transparancy();
    
    function makeAlpha_from_Transparancy()
    {
    	//Выделение прозрачного
      var id4556 = charIDToTypeID( "setd" );
      var desc983 = new ActionDescriptor();
      var id4557 = charIDToTypeID( "null" );
      var ref657 = new ActionReference();
      var id4558 = charIDToTypeID( "Chnl" );
      var id4559 = charIDToTypeID( "fsel" );
      ref657.putProperty( id4558, id4559 );
      desc983.putReference( id4557, ref657 );
      var id4560 = charIDToTypeID( "T   " );
      var ref658 = new ActionReference();
      var id4561 = charIDToTypeID( "Chnl" );
      var id4562 = charIDToTypeID( "Chnl" );
      var id4563 = charIDToTypeID( "Trsp" );
      ref658.putEnumerated( id4561, id4562, id4563 );
      desc983.putReference( id4560, ref658 );
      executeAction( id4556, desc983, DialogModes.NO );
    
    
      //Сохраняем выделение в новый канал
      var id4564 = charIDToTypeID( "Mk  " );
      var desc984 = new ActionDescriptor();
      var id4565 = charIDToTypeID( "Nw  " );
      var id4566 = charIDToTypeID( "Chnl" );
      desc984.putClass( id4565, id4566 );
      var id4567 = charIDToTypeID( "At  " );
      var ref659 = new ActionReference();
      var id4568 = charIDToTypeID( "Chnl" );
      var id4569 = charIDToTypeID( "Chnl" );
      var id4570 = charIDToTypeID( "New " );
      ref659.putEnumerated( id4568, id4569, id4570 );
      desc984.putReference( id4567, ref659 );
      var id4571 = charIDToTypeID( "Usng" );
      var id4572 = charIDToTypeID( "UsrM" );
      var id4573 = charIDToTypeID( "RvlS" );
      desc984.putEnumerated( id4571, id4572, id4573 );
      executeAction( id4564, desc984, DialogModes.NO );
    
    
      var CH =duppedDocument.channels[3];
      duppedDocument.selection.store(CH,SelectionType.REPLACE);
    }
    
    
    
    
    function Save_as_TGA() {
      function step1(enabled, withDialog) {
    	if (enabled != undefined && !enabled)
    	  return;
    	var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    	var desc1 = new ActionDescriptor();
    	desc1.putInteger(cTID('Dpth'), 8);
    	var desc2 = new ActionDescriptor();
    	desc2.putInteger(cTID('Vrsn'), 6);
    	desc2.putEnumerated(cTID('Mthd'), sTID("hdrToningMethodType"), sTID("hdrtype2"));
    	desc2.putDouble(cTID('Exps'), 0);
    	desc2.putDouble(cTID('Gmm '), 1);
    	desc2.putBoolean(sTID("deghosting"), false);
    	desc1.putObject(cTID('With'), sTID("hdrOptions"), desc2);
    	executeAction(sTID('convertMode'), desc1, dialogMode);
      };
    
      function step4(enabled, withDialog) {
    	if (enabled != undefined && !enabled)
    	  return;
    	var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    	var desc1 = new ActionDescriptor();
    	var desc2 = new ActionDescriptor();
    	desc2.putInteger(cTID('BtDp'), 32);
    	desc2.putInteger(cTID('Cmpr'), 1); //RLE Compression
    	desc1.putObject(cTID('As  '), cTID('TrgF'), desc2);
    	desc1.putPath(cTID('In  '), new File(file));
    	desc1.putInteger(cTID('DocI'), 223);
    	executeAction(sTID('save'), desc1, dialogMode);
      };
    
      step1(true,0);      //
      step4();      //
    };
    
    
    
    //=========================================
    //                    Save_as_TGA.main
    //=========================================
    //
    
    Save_as_TGA.main = function () {
      Save_as_TGA();
    };
    
    Save_as_TGA.main();
    duppedDocument.close(SaveOptions.DONOTSAVECHANGES);
    app.activeDocument = doc;
    
    
    August 1, 2011

    reowner1 wrote:

    ...When I save it as PNG transparency shows...

    So what is wrong with PNG?

    Chris Cox
    Legend
    August 1, 2011

    Because so many people using TGA don't understand transparency and alpha -- we only read and write TGA with alpha channels.

    (we tried it with transparency, and half the video industry got confused)

    Noel Carboni
    Noel CarboniCorrect answer
    Legend
    August 1, 2011

    If I recall correctly, for TGA transparency you actually have to save the transparency as an Alpha channel yourself.

    Something along these lines:

    • Make sure you have no selection.
    • Right click on the mask that's giving your layer transparency.
    • Click "Add Mask to Selection".
    • Click the Select menu, choose "Save Selection...", and save it as a new alpha channel in your image, call it Transparency.
    • Make sure "Alpha channels" is checked when saving your image.

    This is purely from memory; I haven't time to test it.

    -Noel

    reowner1Author
    Participant
    August 1, 2011

    Thanks Noel, it works!