Permalink
Browse files

Add Image.orientation property

  • Loading branch information...
dittos committed Apr 25, 2013
1 parent 9935d40 commit 88574468a38015669dae903185fb328abdd717c0
Showing with 46 additions and 1 deletion.
  1. +5 −0 wand/api.py
  2. +25 −1 wand/image.py
  3. +16 −0 wandtests/image.py
@@ -272,6 +272,11 @@ class MagickPixelPacket(ctypes.Structure):
library.MagickGetImageHeight.argtypes = [ctypes.c_void_p]
library.MagickGetImageHeight.restype = ctypes.c_size_t
library.MagickGetImageOrientation.argtypes = [ctypes.c_void_p]
library.MagickGetImageOrientation.restype = ctypes.c_int
library.MagickSetImageOrientation.argtypes = [ctypes.c_void_p, ctypes.c_int]
library.MagickGetImageUnits.argtypes = [ctypes.c_void_p]
library.MagickSetImageUnits.argtypes = [ctypes.c_void_p, ctypes.c_int]
@@ -25,7 +25,7 @@
__all__ = ('ALPHA_CHANNEL_TYPES', 'CHANNELS', 'COMPOSITE_OPERATORS',
'EVALUATE_OPS', 'FILTER_TYPES', 'GRAVITY_TYPES', 'IMAGE_TYPES',
'UNIT_TYPES',
'ORIENTATION_TYPES', 'UNIT_TYPES',
'ChannelDepthDict', 'ChannelImageDict', 'ClosedImageError',
'Image', 'ImageProperty', 'Iterator', 'Metadata', 'OptionDict')
@@ -326,6 +326,13 @@
'center', 'east', 'south_west', 'south', 'south_east',
'static')
#: (:class:`tuple`) The list of :attr:`~Image.orientation` types.
#:
#: .. versionadded:: 0.3.0
ORIENTATION_TYPES = ('undefined', 'top_left', 'top_right', 'bottom_right',
'bottom_left', 'left_top', 'right_top', 'right_bottom',
'left_bottom')
#: (:class:`collections.Set`) The set of available :attr:`~Image.options`.
#:
#: .. versionadded:: 0.3.0
@@ -778,6 +785,23 @@ def height(self, height):
raise TypeError('height must be a integral, not ' + repr(height))
library.MagickSetSize(self.wand, self.width, height)
@property
def orientation(self):
"""(:class:`basestring`) The image orientation. It's a string from
:const:`ORIENTATION_TYPES` list. It also can be set."""
orientation_index = library.MagickGetImageOrientation(self.wand)
return ORIENTATION_TYPES[orientation_index]
@orientation.setter
def orientation(self, value):
if not isinstance(value, basestring):
raise TypeError('expected a string, not ' + repr(value))
elif value not in ORIENTATION_TYPES:
raise ValueError('expected a string from ORIENTATION_TYPES, not '
+ repr(value))
index = ORIENTATION_TYPES.index(value)
library.MagickSetImageOrientation(self.wand, index)
@property
def font_color(self):
return Color(self.options['fill'])
@@ -1147,3 +1147,19 @@ def flop():
assert flopped[-1, 0] == img[0, 0]
assert flopped[0, -1] == img[-1, -1]
assert flopped[-1, -1] == img[0, -1]
@tests.test
def get_orientation():
with Image(filename=asset('sasha.jpg')) as img:
assert img.orientation == 'undefined'
with Image(filename=asset('beach.jpg')) as img:
assert img.orientation == 'top_left'
@tests.test
def set_orientation():
with Image(filename=asset('beach.jpg')) as img:
img.orientation = 'bottom_right'
assert img.orientation == 'bottom_right'

0 comments on commit 8857446

Please sign in to comment.