Closed norlover closed 5 years ago
png图像有RGBA四个通道,而BMP图像只有RGB三个通道,所以PNG转BMP时候程序不知道A通道怎么办,就会产生错误。
http://music.163.com/#/album?id=37016406
id 37016404
在file_util.py的 def resize_img中添加一段代码自行解决了。改完后重新安装一下,添加后如下(来自于一个纯新手的折腾):
def resize_img(file_path, max_size=(640, 640), quality=90): try: img = Image.open(file_path) except IOError: print('Can\'t open image:', file_path) return
if img.size[0] > max_size[0] or img.size[1] > max_size[1]:
img.thumbnail(max_size, Image.ANTIALIAS)
if len(img.split()) == 4:
r, g, b, a = img.split()
img = Image.merge("RGB", (r, g, b))
img.save(file_path, quality=quality)
else:
img.save(file_path, quality=quality)
解决方案可行, 建议发送PR
参考#31 进行修复,感谢@leewp14 的PR和@tao-j 的测试
Traceback (most recent call last): File "C:\Users\lvshui\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pillow-4.3.0-py3.6-win32.egg\PIL\JpegImagePlugin.py", line 605, in _save KeyError: 'RGBA'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Users\lvshui\AppData\Local\Programs\Python\Python36-32\Scripts\ncm-script.py", line 11, in
load_entry_point('netease-cloud-music-dl==0.2.0', 'console_scripts', 'ncm')()
File "C:\Users\lvshui\AppData\Local\Programs\Python\Python36-32\lib\site-packages\netease_cloud_music_dl-0.2.0-py3.6.egg\ncm\start.py", line 76, in main
File "C:\Users\lvshui\AppData\Local\Programs\Python\Python36-32\lib\site-packages\netease_cloud_music_dl-0.2.0-py3.6.egg\ncm\start.py", line 42, in download_playlist_songs
File "C:\Users\lvshui\AppData\Local\Programs\Python\Python36-32\lib\site-packages\netease_cloud_music_dl-0.2.0-py3.6.egg\ncm\downloader.py", line 64, in download_song_by_song
File "C:\Users\lvshui\AppData\Local\Programs\Python\Python36-32\lib\site-packages\netease_cloud_music_dl-0.2.0-py3.6.egg\ncm\file_util.py", line 17, in resize_img
File "C:\Users\lvshui\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pillow-4.3.0-py3.6-win32.egg\PIL\Image.py", line 1928, in save
File "C:\Users\lvshui\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pillow-4.3.0-py3.6-win32.egg\PIL\JpegImagePlugin.py", line 607, in _save
OSError: cannot write mode RGBA as JPEG