在python中仅旋转图像的一部分 [英] rotating only a part of the image in python

查看:461
本文介绍了在python中仅旋转图像的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,在编码方面,我是一个完全菜鸟. 我有一个问题,希望使用Python旋转图像的仅一部分.我已经导入了PIL,并且可以使用旋转功能,但是我不能使其仅旋转图像的一部分.任何帮助将不胜感激.

Sorry, I'm a complete noob when it comes to coding. I've got a question for rotating only a portion of the image using Python. I already have PIL imported and the rotate function working but I can't make it rotate only a portion of the image. Any help would be greatly appreciated.

from PIL import Image
import _imaging
import sys

myImage = Image.open("img.gif")

for x in range():
    for y in range():
        myImage.rotate(90).show()

我有类似的东西

推荐答案

我会提出以下解决方案:

i would propose the following solution:

inlay = img.crop((x1,y1,x2,y2)).rotate(90)
img.paste(inlay, (x1,y1,x2,y2))

x1,y1是镶嵌图像/子图像的左上角,x2,y2是镶嵌图像/子图像的右下角.

x1,y1 is the left upper corner and x2,y2 the lower right corner of the inlay/sub-image.

img =您示例中的myImage

img = myImage from your example

这篇关于在python中仅旋转图像的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆