Rotating PIL image doesn't seem to rotate the canvas (TKinter canvas is not added)
right eye
I have a problem with rotating the created image. Because the code is scattered across many methods, I've listed below the commands I think are relevant.
The problem is, when the image is created successfully, when I rotate the image using img.rotate(-90)... the image rotates, but it looks like the tray/background/canvas is not rotated (see attached image).
How can I correct it. Do I need to create a larger transparent background? Is it possible to make the background/canvas also rotate...or can I rotate and then resize the background/canvas?
First example image (QRCODE)
img = Image.new('RGB', (x,y), 'white')
qr = qrcode.QRCode(version=1,error_correction=qrcode.constants.ERROR_CORRECT_L,box_size=10,border=1,)
qr.add_data('QRB.NO/AbCd1')
qr.make(fit=True)
QRimg = qr.make_image()
img = img.paste(QRimg, (x,y))
img.show() #333
raw_input('(Above is unrotated QRcode image) Press enter...') #333
img = img.rotate(-90)
print img, type(img)
img.show() #333
raw_input('Above is the rotated -90 QRcode image. Press enter...') #333
second example image
font_name = 'Arial.ttf'
font_size = 16
font = ImageFont.truetype(font_name, font_size)
img = Image.new('RGB', (x,y), color=background_color)
# Place text
draw = ImageDraw.Draw(img)
draw.text( (corner_X,corner_Y), 'QRB.NO/AbCd1', font=font, fill='#000000' )
draw.rectangle((0,0,x-1,y-1), outline = "black")
del draw
print img, type(img)
img.show() #333
raw_input('(Above is the unrotated test image). Press enter...') #333
img = img.rotate(90)
print img, type(img)
img.show() #333
raw_input('(Above is the ROTATED 90 text image). Press enter...') #333
output
<PIL.Image.Image image mode=RGB size=71x57 at 0x10E9B8C10> <class 'PIL.Image.Image'>
(Above is unrotated QRcode image) Press enter...
<PIL.Image.Image image mode=RGB size=71x57 at 0x10E9B8F90> <class 'PIL.Image.Image'>
Above is the rotated -90 QRcode image. Press enter...
<PIL.Image.Image image mode=RGB size=57x9 at 0x10EA6CB90> <class 'PIL.Image.Image'>
(Above is the unrotated test image). Press enter...
<PIL.Image.Image image mode=RGB size=57x9 at 0x10E9B8C10> <class 'PIL.Image.Image'>
(Above is the ROTATED 90 text image). Press enter...
edit:
x,y = img.size
img = img.resize( (y, x), Image.ANTIALIAS )
img = img.rotate(-90)
...or...
x,y = img.size
img = img.rotate(-90)
img = img.resize( (y, x), Image.ANTIALIAS )
... doesn't seem to help.
right eye
Figured it out. I'm not going to help others because it seems like a subtle but important distinction.
img = img.transpose(Image.ROTATE_270)
...or...
img = img.transpose(Image.ROTATE_90)