How to use PIL to resize and apply rotation EXIF information to the file?

前端 未结 3 1046
轮回少年
轮回少年 2020-12-07 19:36

I am trying to use Python to resize picture. With my camera, files are all written is landscape way.

The exif information handle a tag to ask the image viewer to rot

3条回答
  •  清歌不尽
    2020-12-07 19:43

    First you have to make sure that your camera actually has a rotation sensor. Most camera models without sensor simply set the Orientation Tag to 1 (Horizontal) for ALL pictures.

    Then I recommend to use pyexiv2 and pyjpegtran in your case. PIL doesn't support lossless rotation, which is the domain of pyjpegtran. pyexiv2 is a library that allows you to copy metadata from one image to another (i think the method name is copyMetadata).

    Are you sure that you don't want to resize your photos before displaying them in the browser? A 8 Megapixel JPEG is much too big for the browser window and will cause endless loading times.

提交回复
热议问题