1

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/1Jepy2Cbecause 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?

gowner
  • 327
  • 1
  • 4
  • 11
  • You could download the N/A image from IFTTT, resize it with Tkinter's methods to make it really small and save to your PC. Then in your code, load an image from IFTTT, resize it, compare it byte-wise against the one you have in your PC. This is a bit extreme though. Isnt there some other way for the server to tell you there is no album cover? – SoreDakeNoKoto Mar 15 '16 at 23:49
  • None that I know of. But in the case of this, where album covers will always be square, while the n/a image by ifttt is rectangular, I can just compare their widths and if they're not equal, I'll know I have the error image. – gowner Mar 16 '16 at 00:01
  • Ah, thats a lot better – SoreDakeNoKoto Mar 16 '16 at 00:04

1 Answers1

1

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.

gowner
  • 327
  • 1
  • 4
  • 11