However, testing it with actual images with various orientation values sometimes led to erroneous results (e.g. I tried Roman Odaisky's solution - it looked comprehensive and clean. I needed a solution that takes care of all orientations, not just 3, 6 and 8. Pass # log.exception("Error applying EXIF Orientation tag") # We'd be here with an invalid orientation value or some random error? If hasattr(im, '_getexif'): # only present in JPEGsĮ = im._getexif() # returns None if no EXIF data :return: A possibly transposed image instance :param Image im: Image instance to inspect The Image instance given to do an in-place rotation. Here's a version that works for all 8 orientations: def flip_horizontal(im): return im.transpose(Image.FLIP_LEFT_RIGHT)ĭef flip_vertical(im): return im.transpose(Image.FLIP_TOP_BOTTOM)ĭef rotate_180(im): return im.transpose(Image.ROTATE_180)ĭef rotate_90(im): return im.transpose(Image.ROTATE_90)ĭef rotate_270(im): return im.transpose(Image.ROTATE_270)ĭef transpose(im): return rotate_90(flip_horizontal(im))ĭef transverse(im): return rotate_90(flip_vertical(im))Įxtract the oritentation EXIF tag from the image, which should be a PIL Image instance,Īnd if there is an orientation tag that would rotate the image, apply that rotation to Imagemagick is another possibility for making batch thumbnails. pyexiv2 may be able to handle EXIF better than the PIL's ExifTags module. I believe it uses the pyexiv2 to handle the EXIF metadata. You could either use this program to make your thumbnails, or look at its source code to see how to do this in Python. Phatch is a batch photo editor written in Python which can handle/preserve EXIF metadata. The easiest solution maybe to use some other program to make thumbnails. Img.thumbnail((1000,1000), Image.ANTIALIAS)īut be aware that the above code may not work for all cameras. Consequently, your smart image viewer will not rotate the image as it did before.įollowing up on Vazquez-Abrams's comment, you can read the metadata using PIL this way, and rotate if necessary: import ExifTagsĮxif=dict((ExifTags.TAGS, v) for k, v in img._getexif().items() if k in ExifTags.TAGS) PIL can read the picture's metadata, but it does not write/copy metadata when you save an Image. Some viewers take note of this metadata and display the image appropriately. Some cameras can detect this and write that info in the picture's EXIF metadata. When a picture is taller than it is wide, it means the camera was rotated. Again I am aware of the resize method but it is Image classes method.Please note that there are better answers below. If an image comes sized bigger than that I want to shrink it to my window.Is there a possible way to do that? Have been looking for docs for a time but all I saw was about Image class not ImageTk. I don't get errors from this code but like I said I want my window size stay 500x500. # I have tried all of the comment rows above in this for loop but could notįoto_label= tk.Label(fotoframe,image=img)įoto_id(row=0,column=0,columnspan=3) Img.append(imobject)# record is definitely binary data I'm looking for. #base64_encoded= base64.b64encode(record) Records=cursor.execute(sql_fetch_blob_query) Sql_fetch_blob_query = """SELECT * from foto """ Here is the code: mydb= nnect('customers.db') So the question is how to resize an ImageTk.PhotoImage object to desired size so that I can display every image without thinking how big they are. So far so good but when it comes a large sized image I have to resize the window all the time. When user click that button it displays an image which stored in db file as binary-BLOB. In it there is a button that says show photos. I'm making a GUI with Tkinter and Sqlite.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |