I am trying to solve a problem with image rotation. I have some PNG image that contains a photo of a solar panel. It is cropped exactly around the panel. I place this image in a satellite map, where it represents its exact real size(say 1x2 meters) in relation to scale. I need to create a Python function that will rotate the original image by a specified angle and create a rotated image with a transparent background around the panel. But the problem is with the size... I need the function to also resize the image so that when I reinsert it into the map, the panel will again represent its real size(1x2m). How to do this? Thank you in advance for any valuable advice or code examples.
Here is example of rotated image(but with bad size)
I tried to use such a function, but it has a problem with the size after inserting it into the map. The panel size is smaller.
def rotate_img(angle):
image_path = '/static/images/panel.png'
rotated_image_path = '/static/images/panel_rotated.png'
original_image = Image.open(image_path).convert("RGBA")
rotation_angle = float(angle)
rotated_image = original_image.rotate(rotation_angle, expand=True,
resample=Image.BICUBIC)
rotated_image.save(rotated_image_path)