Here is some code in python-fu to turn your idea into a plugin.
I thought it might amuse you to have your very own filter entry in your own copy of Gimp.
Copy the lines into a text editor, save the file (perhaps as Racer_Anitalias_Selection) with the extension .py and save it to your plugin folder.
#!/usr/bin/env python
#-*- coding: utf-8 -*-
# Anti-alias request from Racer_X
# A very literal coding of the steps requested
# It works, but can easily go wrong if the user
# tries to apply the plugin with a selection
# on the non-active layer.
from gimpfu import *
def plugin_main(image, layer, shrink_amount, feather_amount):
# Store the GIMP's settings so they can be later restored
gimp.context_push()
# Set start undo point
pdb.gimp_image_undo_group_start(image)
# active_layer = pdb.gimp_image_get_active_layer(image)
# Find out if there is already a selection with
has_selection_original,sx1,sy1,sx2,sy2 = pdb.gimp_selection_bounds(image)
if not has_selection_original:
# if there is not already a selection
# find the currently active layer with
active_layer = pdb.gimp_image_get_active_layer(image)
if active_layer:
# if there is an active layer
# create a selection from the contents of the active layer with
pdb.gimp_image_select_item(image, CHANNEL_OP_REPLACE, active_layer)
else:
# otherwise if there is an existing selection
# make a note of it with
current_selection = pdb.gimp_image_get_selection(image)
# now that we have a selection
# shrink the selection by the amount entered in the dialog UI with
pdb.gimp_selection_shrink(image, shrink_amount)
# and invert the selection with
pdb.gimp_selection_invert(image)
# then feather selection by the amount entered in the dialog UI with
pdb.gimp_selection_feather(image, feather_amount)
if not has_selection_original:
# if there was no selection to begin with
# cut the inverted selection
is_successful = pdb.gimp_edit_cut(active_layer)
else:
# and if there was an initial selection
# Find the currently active layer with
active_layer = pdb.gimp_image_get_active_layer(image)
# cut the inverted selection
is_successful = pdb.gimp_edit_cut(active_layer)
# Finally remove the selection outline with
pdb.gimp_selection_none(image)
# Remove undo point
pdb.gimp_image_undo_group_end(image)
# Restore the GIMP's settings to their original status
gimp.context_pop()
register(
"python_fu_Racer_AntiAliasing",
"Simple Anti-aliasing",
"Simple Anti-aliasing for selection on the active layer",
"Skinnyhouse",
"GPL",
"2018",
"<Image>/Filters/Racer Anti-alias selection on active layer...",
"*",
[
(PF_SPINNER, "pf_shrink", "Shrink selection by:", 1, (1, 3000, 1)),
(PF_SPINNER, "pf_feather", "Feather radius:", 5, (1, 3000, 1)),
],
[],
plugin_main)
main()