Allow float center for rotate operations

This commit is contained in:
Andrew Murray 2024-06-08 19:11:51 +10:00
parent 5bacce9dc2
commit 0d73721c65

View File

@ -2305,7 +2305,7 @@ class Image:
angle: float, angle: float,
resample: Resampling = Resampling.NEAREST, resample: Resampling = Resampling.NEAREST,
expand: int | bool = False, expand: int | bool = False,
center: tuple[int, int] | None = None, center: tuple[float, float] | None = None,
translate: tuple[int, int] | None = None, translate: tuple[int, int] | None = None,
fillcolor: float | tuple[float, ...] | str | None = None, fillcolor: float | tuple[float, ...] | str | None = None,
) -> Image: ) -> Image:
@ -2373,10 +2373,7 @@ class Image:
else: else:
post_trans = translate post_trans = translate
if center is None: if center is None:
# FIXME These should be rounded to ints? center = (w / 2, h / 2)
rotn_center = (w / 2.0, h / 2.0)
else:
rotn_center = center
angle = -math.radians(angle) angle = -math.radians(angle)
matrix = [ matrix = [
@ -2393,10 +2390,10 @@ class Image:
return a * x + b * y + c, d * x + e * y + f return a * x + b * y + c, d * x + e * y + f
matrix[2], matrix[5] = transform( matrix[2], matrix[5] = transform(
-rotn_center[0] - post_trans[0], -rotn_center[1] - post_trans[1], matrix -center[0] - post_trans[0], -center[1] - post_trans[1], matrix
) )
matrix[2] += rotn_center[0] matrix[2] += center[0]
matrix[5] += rotn_center[1] matrix[5] += center[1]
if expand: if expand:
# calculate output size # calculate output size