0

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.

WinEunuuchs2Unix
  • 1,801
  • 1
  • 17
  • 34

1 Answers1

3

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

jizhihaoSAMA
  • 12,336
  • 9
  • 27
  • 49
  • Wouldn't you know I no sooner got `ffmpeg` working (finally) then read your excellent answer. I'll try it tonight and compare speeds to `ffmpeg`. – WinEunuuchs2Unix Jul 29 '20 at 11:51
  • @WinEunuuchs2Unix Glad to know the result of comparsion. – jizhihaoSAMA Jul 29 '20 at 14:25
  • It will take awhile because command: `file = eyeD3.load(r'"' + self.current_song_path + '"')` generates the error: `AttributeError: 'module' object has no attribute 'load' `. I suspect you are using Ubuntu 20.04 or similar with Python 3.8 and not Ubuntu 16.04 LTS like me with Python 2.7. – WinEunuuchs2Unix Jul 30 '20 at 02:18
  • @WinEunuuchs2Unix My device: `Windows 10 + Python 3.7`.The cause maybe is you are using `python2` . – jizhihaoSAMA Jul 30 '20 at 02:33
  • I'm not able to fetch the image. It shows me a white screen instead – KrevoL Aug 20 '22 at 15:06
  • @KrevoL See: https://stackoverflow.com/questions/16424091/why-does-tkinter-image-not-show-up-if-created-in-a-function, Your image maybe garbage collected by python. – jizhihaoSAMA Aug 22 '22 at 08:35