It sounds like you need to know the bounding box of a rotated rectangle. I find that ChatGPT is pretty good at solving these types of small problems. I haven't tested this code, but here is what it gave me. It assumes the sprite is rotated from the topleft corner, but I don't know if you are rotating from the center point or some other pivot.
Prompt: Write a function in Lua that calculates the bounding box of a rotated rectangle, given an x, y, width, height, and angle in degrees.
Answer: Certainly! Here is a function that calculates the bounding box of a rotated rectangle in Lua:
function boundingBox(x, y, w, h, angle)
local function rotate(px, py, ox, oy, angle)
local radians = math.rad(angle)
local s, c = math.sin(radians), math.cos(radians)
return ox + (px  ox) * c  (py  oy) * s, oy + (px  ox) * s + (py  oy) * c
end
local x1, y1 = rotate(x, y, x, y, angle)
local x2, y2 = rotate(x + w, y, x, y, angle)
local x3, y3 = rotate(x, y + h, x, y, angle)
local x4, y4 = rotate(x + w, y + h, x, y, angle)
local minX = math.min(x1, x2, x3, x4)
local maxX = math.max(x1, x2, x3, x4)
local minY = math.min(y1, y2, y3, y4)
local maxY = math.max(y1, y2, y3, y4)
return minX, maxX, minY, maxY
end
This function takes the following arguments:

x
: The xcoordinate of the rectangle's topleft corner

y
: The ycoordinate of the rectangle's topleft corner

w
: The width of the rectangle

h
: The height of the rectangle

angle
: The angle of rotation in degrees
It returns a tuple of four values: the minimum xcoordinate, the maximum xcoordinate, the minimum ycoordinate, and the maximum ycoordinate of the bounding box.
For example, you could use this function like this:
local minX, maxX, minY, maxY = boundingBox(10, 20, 30, 40, 45)
This would calculate the bounding box of a rectangle with topleft corner at (10, 20), width 30, height 40, and 45 degrees of rotation. The function would return the minimum xcoordinate, maximum xcoordinate, minimum ycoordinate, and maximum ycoordinate of the bounding box.