python - How do I stop PIL from swapping height/width when rotating an image 90°? -


i using pil rotate image. works in general, except when rotate image 90° or 270°, in case x , y measurements swap. is, given image:

>>> img.size (93, 64) 

if rotate 89° this:

>>> img.rotate(89).size (93, 64) 

and 91° this:

>>> img.rotate(91).size (93, 64) 

but if rotate either 90° or 270°, find height , width swapped:

>>> img.rotate(90).size (64, 93) >>> img.rotate(270).size (64, 93) 

what's correct way prevent this?

i'm hoping comes more graceful solution, seems work now:

img = image.open('myimage.pbm')  frames = [] angle in range(0, 365, 5):     # rotate image expand=true, makes canvas     # large enough contain entire rotated image.     x = img.rotate(angle, expand=true)      # crop rotated image size of original image     x = x.crop(box=(x.size[0]/2 - img.size[0]/2,                x.size[1]/2 - img.size[1]/2,                x.size[0]/2 + img.size[0]/2,                x.size[1]/2 + img.size[1]/2))      # stuff rotated image here. 

for angles other 90° , 270° results in same behavior if set expand=false , don't bother crop operation.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -