# Scaling StyleBoxTexture without scaling the control?

**URL:** <https://forum.godotengine.org/t/scaling-styleboxtexture-without-scaling-the-control/134758>\
**Category:** UI\
**Tags:** godot-4\
**Created:** [March 6, 2026, 5:27pm UTC](https://forum.godotengine.org/t/scaling-styleboxtexture-without-scaling-the-control/134758 "2026-03-06T17:27:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin\_Uchiha](https://forum.godotengine.org/letter_avatar_proxy/v4/letter/k/e36b37/32.png) [@Kevin\_Uchiha](https://forum.godotengine.org/u/Kevin_Uchiha)\
**Post date:** [March 6, 2026, 5:27pm UTC](https://forum.godotengine.org/t/scaling-styleboxtexture-without-scaling-the-control/134758/1 "2026-03-06T17:27:21Z")

</div>

### Godot Version

Godot v4.6.1 stable mono

### Question

Is it possible to upscale the the texture of a StyleBoxTexture?

My game has pixel graphics. I know i could just change viewport width and height to something that works well with pixel graphics, however, my game also have alot of text and text becomes hard to read at low resolutions. I want high resolution text but everything else low resolution. My target resolution is 1080x2400 (for android phone). My camera has zoom 8, meaning each pixel takes up 8x8 on screen. I also want the pixels for the GUI/Controls to take up 8x8, except for the text.

There is no scale setting in StyleBoxTexture. If i upscale a panel by setting scale in transform to 8, the StyleBoxTexture gets the correct size, however, i cannot scale things within a Container. Also anchors start behaving weirdly if i mess with scaling.

Of course, the simplest solution would be to just upscale the actual png file used in the StyleBoxTexture. However, i would like to avoid doing that if possible.

How can i upscale GUI textures without effecting the actual control logic/setup and have text that is not upscaled? Is it even possible, or is my only option to upscale the actual source image?

---

<div class="post-metadata">

**Author:** ![leofleeo](https://forum.godotengine.org/letter_avatar_proxy/v4/letter/l/b5ac83/32.png) [@leofleeo](https://forum.godotengine.org/u/leofleeo)\
**Post date:** [May 25, 2026, 6:19pm UTC](https://forum.godotengine.org/t/scaling-styleboxtexture-without-scaling-the-control/134758/2 "2026-05-25T18:19:02Z")

</div>

I had this exact issue, and I made a script to fix it. Just put it on the StyleBoxTexture. Here it is:

```gdscript
extends StyleBoxTexture

@export var texture_scale: int = 1:
	set(value):
		texture_scale = value
		resize(value)

func resize(scale: int) -> void:
	self.texture_margin_left = self.texture_margin_left * scale
	self.texture_margin_top = self.texture_margin_top * scale
	self.texture_margin_right = self.texture_margin_right * scale
	self.texture_margin_bottom = self.texture_margin_bottom * scale
	var tex: Texture2D = self.texture
	var img: Image = tex.get_image()
	var new_size: Vector2i = Vector2i(tex.get_size() * scale)
	img.resize(new_size.x, new_size.y, Image.INTERPOLATE_NEAREST)
	self.texture = ImageTexture.create_from_image(img)

```

Only problems is that the minimum size doesn’t seem to update, and that it doesn’t show in the theme preview or the editor. When actually running the game, it works just fine.

---

<div class="post-metadata">

**Author:** ![alex\_may](https://forum.godotengine.org/user_avatar/forum.godotengine.org/alex_may/32/35610_2.png) [@alex\_may](https://forum.godotengine.org/u/alex_may)\
**Post date:** [December 4, 2026, 10:43am UTC](https://forum.godotengine.org/t/scaling-styleboxtexture-without-scaling-the-control/134758/3 "2026-12-04T10:43:52Z")

</div>

Lifesaver, this is a great script!

Add @tool and that sorts the preview issue

---

<div class="post-metadata">

**Author:** ![alex\_may](https://forum.godotengine.org/user_avatar/forum.godotengine.org/alex_may/32/35610_2.png) [@alex\_may](https://forum.godotengine.org/u/alex_may)\
**Post date:** [December 4, 2026, 12:14pm UTC](https://forum.godotengine.org/t/scaling-styleboxtexture-without-scaling-the-control/134758/4 "2026-12-04T12:14:46Z")

</div>

Hmm actually since it makes a copy of the texture each time you end up stacking scales. Need to rethink it. This version requires you to make two resources, one original StyleBoxTexture and one new ScaledStyleBoxTexture resource that references the original.

```auto
@tool
class_name ScaledStyleBoxTexture
extends StyleBoxTexture

@export var reference_style_box : StyleBoxTexture = null

@export var texture_scale: int = 1:
	set(value):
		texture_scale = value
		resize(value)

func resize(scale: int) -> void:
	if !reference_style_box: return
	
	axis_stretch_horizontal = reference_style_box.axis_stretch_horizontal
	axis_stretch_vertical = reference_style_box.axis_stretch_vertical
	draw_center = reference_style_box.draw_center
	var r = reference_style_box.region_rect
	region_rect = Rect2(r.position * scale, r.size * scale)
	expand_margin_left = reference_style_box.expand_margin_left * scale
	expand_margin_right = reference_style_box.expand_margin_right * scale
	expand_margin_top = reference_style_box.expand_margin_top * scale
	expand_margin_bottom = reference_style_box.expand_margin_bottom * scale
	texture_margin_left = reference_style_box.texture_margin_left * scale
	texture_margin_right = reference_style_box.texture_margin_right * scale
	texture_margin_top = reference_style_box.texture_margin_top * scale
	texture_margin_bottom = reference_style_box.texture_margin_bottom * scale
	
	var tex: Texture2D = reference_style_box.texture
	var img: Image = tex.get_image()
	var new_size: Vector2i = Vector2i(tex.get_size() * scale)
	img.resize(new_size.x, new_size.y, Image.INTERPOLATE_NEAREST)
	texture = ImageTexture.create_from_image(img)

```
