How to make transparent pixels opaque

I’d like to be able to quickly remove any transparent pixels from a layer by making them opaque. Currently I can do this by using Adjustments > Hue/Saturation and turning the Alpha channel up to 100 multiple times.

Is there a better method to do this and if not how can I access the function via scripting?

Thanks

You can call hue saturation through script with something like this:

app.command.HueSaturation {
    alpha = 100,
    channels = FilterChannels.RGBA,
    mode = 0,
    ui = false
}

When ui is false, the script executes without opening up a dialog window. A keyboard shortcut can be assigned to the script through Edit > Keyboard Shortcuts.

Edit: Whether to target selected or all can be found in preferences: app.preferences.filters.cels_target. I think all is 1 and selected is 0.

The documentation on the command is here.

Keep in mind that pixels may also appear translucent or transparent due to cel opacity and/or layer opacity.

For finer control, iterate through the pixels of an image in each cel of a layer. There are three ways to read and write image pixels: get/set methods, pixel iterator and string bytes. The details depend on the sprite’s color mode; indexed, for example, would work differently than RGB. Tile map layers work differently as well.

Different users might have different expectations for how to handle pixels that are already zero alpha in an image – i.e., completely transparent, not translucent. Aseprite regularly trims cel images of excess alpha so they are smaller than the sprite canvas and places them at an offset. So you’d have to say more if you want behavior other than what the hue sat command does.

1 Like

Worked great, thank you very much.

For future reference for any others, I added a for loop that runs the function 9 times in a row, any transparent pixels will become opaque when this script is run.

for i = 9,1,-1 
do 
   app.command.HueSaturation {
  ui=false,
  channels=FilterChannels.RGBA,
  mode='hsl',
  alpha=100
}
end

Sounds like a bug with the command. I don’t think the arguments are bounds checked, so you could try calling once with alpha = 25500 (255 * 100) to remove all opacity. The filter can take a sec to apply to bigger pictures so calling once could speed things up.

1 Like