Hi, I have 2 things I'd like help with:
1) is there a way to find the exact center of my screen?
2) a loop

Here's what I need the loop for:

image = ImageGrab.grab((0,0,800,800))
box = (100,100,400,400)
im = image.crop(box)
im1 = im.save("screen.jpg")
# at this point I need to rotate the image 90 degrees and crop it again, but do this four times-
# so I'd like a loop here instead of this:
im2 = im1.rotate(90)
im3 = im2.crop(box)
im4 = im3.save("screen1.jpg")
im5 = im4.rotate(90)
im6 = im5.crop(box)
im7 = im6.save("screen2.jpg")
#you get the idea ;)  I did try something like this:
# for i in range(3):
#       im,im1,im2
#but that doesn't work

any help?

I can try to help with #2. First, change im, im1, im2, etc to strings, so that the command for im looks like im = "image.crop(box)" . The value should be a string. When you want to call that specific command use exec im1 etc for each command.

#2 I am not sure, but methods crop() and rotate() should return image objects. If so, you could simply:

for n in range(1, 4):
    im1 = im1.rotate(90).crop(box)
    im1.save("screen%s.jpg" % n)

#2 I am not sure, but methods crop() and rotate() should return image objects. If so, you could simply:

for n in range(1, 4):
    im1 = im1.rotate(90).crop(box)
    im1.save("screen%s.jpg" % n)

This looks good but when I try it, it will only rotate 1 time and then save 3 jpgs of it.

This looks good but when I try it, it will only rotate 1 time and then save 3 jpgs of it.

I guess the rotate method does not return the rotated object. Try this:

for n,r in enumerate([90,180,270]):
    im1.rotate(r).crop(box) # ? im1 = im1.rotate(r).crop(box)
    im1.save("screen%s.jpg" % (n+1))

I guess the rotate method does not return the rotated object. Try this:

for n,r in enumerate([90,180,270]):
    im1.rotate(r).crop(box) # ? im1 = im1.rotate(r).crop(box)
    im1.save("screen%s.jpg" % (n+1))

Thank you!

This question has already been answered. Start a new discussion instead.