1
\$\begingroup\$

What do you think of this code? I want to keep an unified interface (treat filepath or image interchangeably) but i have heard try except is the prefered way, how would you do?

def rotate_img(imageref, deg):
"""
Rotate from [deg] degree the input image
param imageref: can be imagepath or ndarray image
param deg: number of rotation degree desired
"""
if isinstance(imageref,np.ndarray):
    from scipy import ndimage
    img = imageref
    img_rt = ndimage.rotate(img, deg, reshape=False)
elif isinstance(imageref,str): 
    img = Image.open(imageref)
    img_rt = img.rotate(deg, expand=1)
else:
    raise('Unknown Type')
return img_rt
\$\endgroup\$
1
  • \$\begingroup\$ Welcome to code review. Please note that you need to post your full working code for us to review it. Also, edit your question so that the title states what your code does. For more information, please read How to Ask. As it is now, your question requires more details \$\endgroup\$ – Aryan Parekh Oct 21 '20 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.