cropping a random part of an image

Peter Otten __peter__ at web.de
Tue Aug 9 10:30:18 EDT 2016


drewes.mil at gmail.com wrote:

> I'm new to python and I have 30.000 pictures.
> I need to crop, let's say 100, parts of 256x256, randomly out of every
> picture.
> 
> I cant find an answer in the net, would be nice if someone could help me
> out!

You can walk over the files with

https://docs.python.org/dev/library/os.html#os.walk

find out the image size and process the image with pillow

http://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.size
http://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.crop

using

https://docs.python.org/dev/library/random.html

to determine what part of an image you want to pick.

Now write some code and come back here if you run into problems you cannot 
solve yourself.




More information about the Python-list mailing list