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.
答案 0 :(得分:3)
It looks like the script is successfully rotating Pictures/image.png
and saving it in your output
directory. But it doesn't stop there: glob
iterates its way into the output
folder, and rotates all of those pictures too. So your original output/image.png
gets overwritten with a copy of output/image.png
, except rotated 180 degrees. In other words, it's your original image, rotated 360 degrees - an identical copy.
You should make sure that glob
doesn't iterate over the output
directory. You could move output
to somewhere other than home/lol/Pictures
. Or perhaps you could manually skip over the output directory, with something like if "/output/" in image: continue
.