wagtail / Willow

A wrapper that combines the functionality of multiple Python image libraries into one API
https://willow.wagtail.org/
BSD 3-Clause "New" or "Revised" License
274 stars 53 forks source link

Orientation API #71

Open kaedroho opened 5 years ago

kaedroho commented 5 years ago

Split from: https://github.com/wagtail/Willow/pull/52#issuecomment-470524069

This API would add support for rotations (in 90 degree increments), flipping and transposition of images.

The Orientation class.

This class represents a particular orientation. Orientations can be added or subtracted.

They can be constructed using one of the following methods:

Orientation.default()
Orientation.rotate(angle)  # angle must be in increments of 90
Orientation.flip_horizontal()
Orientation.flip_vertical()

The .get_exif_orientation() operation

Orientation can also be taken from the image's EXIF data using a new get_exif_orientation operation.

The .orient() operation

This takes an orientation object and applies it to the image.

transformed_image = image.orient(image.get_exif_orientation() + Orientation.flip_vertical() + Orientation.rotate(90))