Sep-12-2022, 07:32 PM
You don't call you function in code you show and error message make no sense.
The code dos work,could be nicer i clean it up a bit,i would have spilt it in two function.
I did answer about virtual environment in your other post
The code dos work,could be nicer i clean it up a bit,i would have spilt it in two function.
I did answer about virtual environment in your other post
from PIL import Image, ImageOps def cropImage(image): print('\n running cropImage() ... \n') print('\n you need crop coordinates for each column \n') # Opens an image in RGB mode im = Image.open(image) im.show() width, height = im.size print('This image is: ', width, ' wide and ', height, ' high') accept = ['yes'] answer = 'X' while not answer in accept: corners = input('Enter your 4 numbers, separated by a space ... ') left, top, right, bottom = [int(i) for i in corners.split()] im1 = im.crop((left, top, right, bottom)) # Shows the image in image viewer im1.show() print('Do you accept this image') answer = input('Enter yes to accept, anything else to try again ') if answer == 'yes': print('image crop coordinates saved to tup ... ') return (left, top, right, bottom) if __name__ == '__main__': image = 'forest.png' crop_tup = cropImage(image) print(crop_tup)Test,it show image have to close image to continue to user input.
G:\div_code\image_env λ python cro1.py running cropImage() ... you need crop coordinates for each column This image is: 800 wide and 292 high Enter your 4 numbers, separated by a space ... 50 100 200 250 Do you accept this image Enter yes to accept, anything else to try again yes image crop coordinates saved to tup ... (50, 100, 200, 250)