 	}
 
 
-	public var clipsImageToPadding = false {
-		didSet {
-			guard clipsImageToPadding != oldValue else {
-				return
-			}
-
-			if image != nil && !padding.isEmpty {
-				setNeedsUpdateContents()
-			}
-
-			invalidateConfiguration()
-		}
-	}
-
-
-	private func computeDrawFrame() -> CGRect {
+	private func computeImageLayerFrame() -> CGRect {
 		guard let image = image else {
 			return .zero
 		}
 
 		let imageSize = image.size
-		let availableFrame = CGRect(size: bounds.size).insetBy(padding)
-
-		guard !imageSize.isEmpty && availableFrame.width > 0 && availableFrame.height > 0 else {
+		let maximumImageLayerFrame = CGRect(size: bounds.size).insetBy(padding)
+
+		guard imageSize.isPositive && maximumImageLayerFrame.size.isPositive else {
 			return .zero
 		}
-
-		var drawFrame = CGRect()
 
 		let gravity = self.gravity
 		let scaling = self.scaling
 
+		var imageLayerFrame = CGRect()
+
 		switch scaling {
 		case .FitIgnoringAspectRatio:
-			drawFrame.size = availableFrame.size
+			imageLayerFrame.size = maximumImageLayerFrame.size
 
 		case .FitInside, .FitOutside:
-			let horizontalScale = availableFrame.width / imageSize.width
-			let verticalScale = availableFrame.height / imageSize.height
+			let horizontalScale = maximumImageLayerFrame.width / imageSize.width
+			let verticalScale = maximumImageLayerFrame.height / imageSize.height
 			let scale = (scaling == .FitInside ? min : max)(horizontalScale, verticalScale)
 
-			drawFrame.size = imageSize.scaleBy(scale)
+			imageLayerFrame.size = imageSize.scaleBy(scale)
 
 		case .FitHorizontally:
-			drawFrame.width = availableFrame.width
-			drawFrame.height = imageSize.height * (drawFrame.width / imageSize.width)
+			imageLayerFrame.width = maximumImageLayerFrame.width
+			imageLayerFrame.height = imageSize.height * (imageLayerFrame.width / imageSize.width)
 
 		case .FitHorizontallyIgnoringAspectRatio:
-			drawFrame.width = availableFrame.width
-			drawFrame.height = imageSize.height
+			imageLayerFrame.width = maximumImageLayerFrame.width
+			imageLayerFrame.height = imageSize.height
 
 		case .FitVertically:
-			drawFrame.height = availableFrame.height
-			drawFrame.width = imageSize.width * (drawFrame.height / imageSize.height)
+			imageLayerFrame.height = maximumImageLayerFrame.height
+			imageLayerFrame.width = imageSize.width * (imageLayerFrame.height / imageSize.height)
 
 		case .FitVerticallyIgnoringAspectRatio:
-			drawFrame.height = availableFrame.height
-			drawFrame.width = imageSize.width
+			imageLayerFrame.height = maximumImageLayerFrame.height
+			imageLayerFrame.width = imageSize.width
 
 		case .None:
-			drawFrame.size = imageSize
+			imageLayerFrame.size = imageSize
 		}
 
 		switch gravity.horizontal {
 		case .Left:
-			drawFrame.left = availableFrame.left
+			imageLayerFrame.left = maximumImageLayerFrame.left
 
 		case .Center:
-			drawFrame.horizontalCenter = availableFrame.horizontalCenter
+			imageLayerFrame.horizontalCenter = maximumImageLayerFrame.horizontalCenter
 
 		case .Right:
-			drawFrame.right = availableFrame.right
+			imageLayerFrame.right = maximumImageLayerFrame.right
 		}
 
 		switch gravity.vertical {
 		case .Top:
-			drawFrame.top = availableFrame.top
+			imageLayerFrame.top = maximumImageLayerFrame.top
 
 		case .Center:
-			drawFrame.verticalCenter = availableFrame.verticalCenter
+			imageLayerFrame.verticalCenter = maximumImageLayerFrame.verticalCenter
 
 		case .Bottom:
-			drawFrame.bottom = availableFrame.bottom
-		}
-		
-		drawFrame = alignToGrid(drawFrame)
-		return drawFrame
-	}
-
-
-	@available(*, unavailable, message="Use .gravity and .scaleMode instead.")
+			imageLayerFrame.bottom = maximumImageLayerFrame.bottom
+		}
+
+		switch image.imageOrientation {
+		case .Left, .LeftMirrored, .Right, .RightMirrored:
+			let center = imageLayerFrame.center
+			swap(&imageLayerFrame.width, &imageLayerFrame.height)
+			imageLayerFrame.center = center
+
+		case .Down, .DownMirrored, .Up, .UpMirrored:
+			break
+		}
+
+		imageLayerFrame = alignToGrid(imageLayerFrame)
+
+		return imageLayerFrame
+	}
+
+
+	private func computeImageLayerTransform() -> CGAffineTransform {
+		guard let image = image else {
+			return CGAffineTransformIdentity
+		}
+
+		// TODO support mirrored variants
+		let transform: CGAffineTransform
+		switch image.imageOrientation {
+		case .Down:          transform = CGAffineTransformMakeRotation(.Pi)
+		case .DownMirrored:  transform = CGAffineTransformMakeRotation(.Pi)
+		case .Left:          transform = CGAffineTransformMakeRotation(-.Pi / 2)
+		case .LeftMirrored:  transform = CGAffineTransformMakeRotation(-.Pi / 2)
+		case .Right:         transform = CGAffineTransformMakeRotation(.Pi / 2)
+		case .RightMirrored: transform = CGAffineTransformMakeRotation(.Pi / 2)
+		case .Up:            transform = CGAffineTransformIdentity
+		case .UpMirrored:    transform = CGAffineTransformIdentity
+		}
+
+		return transform
+	}
+
+
+	@available(*, unavailable, message="Use .gravity and .scaling instead.")
 	public final override var contentMode: UIViewContentMode {
 		get { return super.contentMode }
 		set { super.contentMode = newValue }

				return
			}

			if image != nil {
				setNeedsUpdateContents()
			}

			invalidateConfiguration()
		}

		didRetrieveImage(image)
	}
}



private final class Layer: CALayer {

	private override func actionForKey(event: String) -> CAAction? {
		return nil
	}
}
