[英]Just rotate image
what is my mistake? 我怎么了
I just want to rotate original image and save him to output folder. 我只想旋转原始图像并将其保存到输出文件夹。
from pathlib import Path
from PIL import Image, ImageFilter
for image in Path('/home/lol/Pictures').glob('**/*.png'):
img = Image.open(image)
img = img.rotate(180)
img.save('/home/lol/Pictures/output/{}'.format(image.name))
print('Done: {}'.format(image))
Console output: 控制台输出:
Done: /home/lol/Pictures/image.png
Done: /home/lol/Pictures/output/image.png
And the picture in output is the same like original. 并且输出中的图片与原始图片相同。
It looks like the script is successfully rotating Pictures/image.png
and saving it in your output
directory. 脚本似乎成功旋转了
Pictures/image.png
并将其保存在output
目录中。 But it doesn't stop there: glob
iterates its way into the output
folder, and rotates all of those pictures too. 但这并不止于此:
glob
遍历output
文件夹,并旋转所有这些图片。 So your original output/image.png
gets overwritten with a copy of output/image.png
, except rotated 180 degrees. 所以,你的原始
output/image.png
获取与副本覆盖output/image.png
,除了旋转180度。 In other words, it's your original image, rotated 360 degrees - an identical copy. 换句话说,它是您的原始图像,旋转了360度-完全相同。
You should make sure that glob
doesn't iterate over the output
directory. 您应该确保
glob
不会遍历output
目录。 You could move output
to somewhere other than home/lol/Pictures
. 您可以将
output
移动到home/lol/Pictures
之外的其他地方。 Or perhaps you could manually skip over the output directory, with something like if "/output/" in image: continue
. 或者,您可以手动跳过输出目录,例如
if "/output/" in image: continue
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.