My Tkinter GUI loads the album cover of a certain song/artist combination directly from the associated last.fm link (looks like this: http://ift.tt/1Jepy2C
because it's fetched by ifttt.com and redirects to the png file on last.fm.)
When there is no album cover on last.fm, ifttt redirects to this picture instead: https://ifttt.com/images/no_image_card.png
.
The problem is that this image has different dimensions than the square album covers, which means I made a "N/A" png file which I would insert if I received that picture. Unfortunately, simply going like this:
from tkinter import *
local_copy_of_not_available_image = PhotoImage(file="album_not_found.png")
internet_image = PhotoImage(data=b64_Album_data) # fetched b64 data through urllib, which should contain either an album cover or the n/a picture above
if internet_image == local_copy_of_not_available_image:
actual_image = PhotoImage(file="my_album_not_found_square_replacement_picture.png")
else:
actual_image = PhotoImage(data=b64_Album_data)
cover = Label(root, image=actual_image)
cover.pack()
mainloop()
doesn't work. Apparently, even though they are the same image, the b64 data in the internet_image
is not the same as the file loaded from my hard drive.
My question is, how can I check if two images are the exact same in terms of raw data, in order to detect when ifttt deliver their n/a picture to me?
I've solved it purely on the basis that all album covers coming from last.fm are square 300x300px images. Since the n/a image coming from ifttt is rectangular, wider than it is high, I have a few possibilities:
1) Checking the aspect ratio. If it's not 1, I have no cover image.
2) Just checking the downloaded image's width. If it's not 300px, I have no cover image.
3) Comparing the downloaded image's width with that of my local copy of the error image. If they're equal, I have no cover image.