gpt4 book ai didi

python - 在 Tkinter 中找到相同的图像?

转载 作者:太空宇宙 更新时间:2023-11-03 16:49:17 25 4
gpt4 key购买 nike

我的 Tkinter GUI 直接从关联的 last.fm 链接加载特定歌曲/艺术​​家组合的专辑封面(如下所示:http://ift.tt/1Jepy2C因为它是由ifttt.com 并重定向到 last.fm 上的 png 文件。)当 last.fm 上没有专辑封面时,ifttt 会重定向到此图片:https://ifttt.com/images/no_image_card.png

问题是这张图片的尺寸与方形专辑封面的尺寸不同,这意味着我制作了一个“N/A”png 文件,如果我收到该图片,我会插入该文件。不幸的是,就像这样:

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()

不起作用。显然,即使它们是相同的图像,internet_image 中的 b64 数据与从我的硬盘加载的文件并不相同。我的问题是,如何检查两个图像的原始数据是否完全相同,以便检测 ifttt 何时将其不可用的图片发送给我?

最佳答案

我解决这个问题纯粹是因为来自last.fm的所有专辑封面都是方形的300x300px图像。由于来自 ifttt 的 n/a 图像是矩形,宽度大于高度,所以我有几种可能性:

1) 检查宽高比。如果不是 1,我就没有封面图片。

2) 仅检查下载图像的宽度。如果不是 300px,我就没有封面图片。

3) 将下载的图像的宽度与错误图像的本地副本的宽度进行比较。如果它们相等,我就没有封面图片。

关于python - 在 Tkinter 中找到相同的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36024194/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com