mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-09 17:00:12 +01:00
Support application and launchable-activity icons as fallback
This commit is contained in:
parent
5d5a4df7d1
commit
77b6974303
@ -38,9 +38,12 @@ from PIL import Image
|
|||||||
def get_densities():
|
def get_densities():
|
||||||
return ['640', '480', '320', '240', '160', '120']
|
return ['640', '480', '320', '240', '160', '120']
|
||||||
|
|
||||||
def launcher_size(density):
|
def dpi_to_px(density):
|
||||||
return (int(density) * 48) / 160
|
return (int(density) * 48) / 160
|
||||||
|
|
||||||
|
def px_to_dpi(px):
|
||||||
|
return (int(px) * 160) / 48
|
||||||
|
|
||||||
def get_icon_dir(repodir, density):
|
def get_icon_dir(repodir, density):
|
||||||
if density is None:
|
if density is None:
|
||||||
return os.path.join(repodir, "icons")
|
return os.path.join(repodir, "icons")
|
||||||
@ -277,7 +280,7 @@ def resize_icon(iconpath, density):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
im = Image.open(iconpath)
|
im = Image.open(iconpath)
|
||||||
size = launcher_size(density)
|
size = dpi_to_px(density)
|
||||||
|
|
||||||
if any(length > size for length in im.size):
|
if any(length > size for length in im.size):
|
||||||
oldsize = im.size
|
oldsize = im.size
|
||||||
@ -483,10 +486,24 @@ def scan_apks(apps, apkcache, repodir, knownapks):
|
|||||||
del thisinfo['icons_src'][density]
|
del thisinfo['icons_src'][density]
|
||||||
empty_densities.append(density)
|
empty_densities.append(density)
|
||||||
|
|
||||||
resize_icon(icondest, density)
|
|
||||||
|
|
||||||
if '-1' in thisinfo['icons_src']:
|
if '-1' in thisinfo['icons_src']:
|
||||||
pass #TODO
|
iconsrc = thisinfo['icons_src']['-1']
|
||||||
|
iconpath = os.path.join(
|
||||||
|
get_icon_dir(repodir, None), iconfilename)
|
||||||
|
iconfile = open(iconpath, 'wb')
|
||||||
|
iconfile.write(apk.read(iconsrc))
|
||||||
|
iconfile.close()
|
||||||
|
im = Image.open(iconpath)
|
||||||
|
dpi = px_to_dpi(im.size[0])
|
||||||
|
for density in densities:
|
||||||
|
if density in thisinfo['icons']:
|
||||||
|
break
|
||||||
|
if dpi >= int(density):
|
||||||
|
thisinfo['icons'][density] = iconfilename
|
||||||
|
shutil.move(iconpath,
|
||||||
|
os.path.join(get_icon_dir(repodir, density), iconfilename))
|
||||||
|
empty_densities.remove(density)
|
||||||
|
break
|
||||||
|
|
||||||
apk.close()
|
apk.close()
|
||||||
|
|
||||||
@ -507,7 +524,7 @@ def scan_apks(apps, apkcache, repodir, knownapks):
|
|||||||
iconpath = os.path.join(
|
iconpath = os.path.join(
|
||||||
get_icon_dir(repodir, density), iconfilename)
|
get_icon_dir(repodir, density), iconfilename)
|
||||||
im = Image.open(last_iconpath)
|
im = Image.open(last_iconpath)
|
||||||
size = launcher_size(density)
|
size = dpi_to_px(density)
|
||||||
|
|
||||||
im.thumbnail((size, size), Image.ANTIALIAS)
|
im.thumbnail((size, size), Image.ANTIALIAS)
|
||||||
im.save(iconpath, "PNG")
|
im.save(iconpath, "PNG")
|
||||||
@ -531,6 +548,11 @@ def scan_apks(apps, apkcache, repodir, knownapks):
|
|||||||
|
|
||||||
empty_densities.remove(density)
|
empty_densities.remove(density)
|
||||||
|
|
||||||
|
for density in densities:
|
||||||
|
icon_dir = get_icon_dir(repodir, density)
|
||||||
|
icondest = os.path.join(icon_dir, iconfilename)
|
||||||
|
resize_icon(icondest, density)
|
||||||
|
|
||||||
# Copy from icons-mdpi to icons since mdpi is the baseline density
|
# Copy from icons-mdpi to icons since mdpi is the baseline density
|
||||||
shutil.copyfile(
|
shutil.copyfile(
|
||||||
os.path.join(get_icon_dir(repodir, '160'), iconfilename),
|
os.path.join(get_icon_dir(repodir, '160'), iconfilename),
|
||||||
|
Loading…
Reference in New Issue
Block a user