Configuring image size of an options buttion icon that was added with code

Godot Version

4.6.1

Question

“$card_selector” is an options button and this code adds png’s to it remotely which works fine in theory but you don’t seem to be able to scale down the png’s so it covers most of the screen when you open it.

$card_selector.add_item(i, counting)
$card_selector.set_item_icon(counting, load(png_path))

Can one resize the icon/texture as it loads in somehow? (and no i can’t do it in the editor since the point of the program is to work with external files) i already tried resize() but it didn’t work no matter how i tried to use it though maybe i still just did it wrong i dunno.

The size cap on popup item icons is a theme constant rather than anything on the texture. It’s icon_max_width on the PopupMenu, and the height follows the aspect ratio, so one number covers it:

$card_selector.get_popup().add_theme_constant_override("icon_max_width", 32)

The OptionButton takes that same constant for the icon it draws on the closed button, so you’d want it in both places.

If you want an exact size rather than a ceiling, resize the Image before it ever becomes a texture. resize() is an Image method and not a Texture2D one, so if you were calling it on what load() gave back, that could be why nothing happened:

var img := Image.load_from_file(png_path)
img.resize(32, 32, Image.INTERPOLATE_LANCZOS)
$card_selector.set_item_icon(counting, ImageTexture.create_from_image(img))