How to get artwork into Tkinter Image using eyed3?

723 views Asked by At

Similar to this question:

I'd like to get music artwork from a .m4a file (similar to `.mp3') into Tkinter Image for displaying on a label.

For some strange reason all the answers in the link use:

import eyed3

but I have to use

import eyeD3

to install I had to use:

sudo apt install python-eyed3
sudo apt install eyed3

I'm running Ubuntu 16.04.6 LTS until 2021 at the latest which means I'm using Python 2.7.12. I understand the syntax and naming conventions may have changed in eyeD3 or eyed3 Python 3.5 versions which is another option for Ubuntu 16.04.6 LTS. I'm also using Linux Kernel 4.14.188 LTS but I doubt that matters.

Note: I tried ffmpeg calls from Python this morning to convert .m4a file's artwork into a .jpg file but that was "complicated" and I was hoping eyed3 or eyeD3 would be simpler.

1

There are 1 answers

6
jizhihaoSAMA On BEST ANSWER

Use file.tag.images and iterate it,use i.image_data to get the bytes of the image.

For example:

import eyed3, io
from PIL import Image, ImageTk
import tkinter as tk

root = tk.Tk()
file = eyed3.load(r"music_path")

# if there contains many images
for i in file.tag.images: 
     img = ImageTk.PhotoImage(Image.open(io.BytesIO(i.image_data)))
     tk.Label(root, image=img).pack()

# or if there only one image here:

# img = ImageTk.PhotoImage(Image.open(io.BytesIO(file.tag.images[0].image_data)))
# tk.Label(root, image=img).pack()

root.mainloop()

Works fine on my PC. enter image description here