1

I was thinking, that I could shear an image around center by first translating it, then shearing, then translating back.

def translate(im: Image.Image, tx: float=0, ty: float=0):
    return im.transform(im.size, Image.AFFINE, (1, 0, tx, 0, 1, ty))

def shear(im: Image.Image, cx=0, cy=0):
    center = [xy/2 for xy in im.size]
    im = translate(im, center[0], center[1])
    im = im.transform(im.size, Image.AFFINE, (1, cx, 0, cy, 1, 0))
    im = translate(im, -center[0], -center[1])
    return im

Unfortunately, translation looses information and I get the following

enter image description here enter image description here

Dims
  • 47,675
  • 117
  • 331
  • 600
  • What about pasting the image into the center of larger one, so the information is not lost on transformation? – taras Jun 30 '18 at 21:31
  • See this post for an example of how to add borders: https://stackoverflow.com/questions/11142851/adding-borders-to-an-image-using-python – Zev Jun 30 '18 at 22:05
  • @taras it's ok, but I don't know the required size; transformation library should do this automatically – Dims Jul 01 '18 at 18:00

0 Answers0