From: Daniel Martí Date: Tue, 7 Jan 2014 11:20:24 +0000 (+0100) Subject: Finish TODO; Fill missing icon densities the best we can X-Git-Tag: 0.1~23^2~33 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=cdcbb082691dc990b281f99d6bd13e5421863900;p=fdroidserver.git Finish TODO; Fill missing icon densities the best we can --- diff --git a/fdroidserver/update.py b/fdroidserver/update.py index 2c359507..b274dab3 100644 --- a/fdroidserver/update.py +++ b/fdroidserver/update.py @@ -451,8 +451,9 @@ def scan_apks(apps, apkcache, repodir, knownapks): thisinfo['versioncode']) # Extract the icon file... + densities = get_densities() empty_densities = [] - for density in get_densities(): + for density in densities: label = icon_dens_label(density) if density not in thisinfo['icons_src']: empty_densities.append(density) @@ -478,7 +479,46 @@ def scan_apks(apps, apkcache, repodir, knownapks): resize_icon(icondest, density) - # TODO: Handle empty_densities + last_density = None + # First try resizing down to not lose quality + for density in densities: + if density not in empty_densities: + last_density = density + continue + if last_density is None: + continue + if options.verbose: + print "Density %s not available, resizing down from %s" % ( + density, last_density) + + last_iconpath = os.path.join( + get_icon_dir(repodir, last_density), iconfilename) + iconpath = os.path.join( + get_icon_dir(repodir, density), iconfilename) + im = Image.open(last_iconpath) + size = launcher_size(density) + + im.thumbnail((size, size), Image.ANTIALIAS) + im.save(iconpath, "PNG") + empty_densities.remove(density) + + last_density = None + # Then just copy from the highest resolution available + for density in reversed(densities): + if density not in empty_densities: + last_density = density + continue + if last_density is None: + continue + if options.verbose: + print "Density %s not available, copying from lower density %s" % ( + density, last_density) + + shutil.copyfile( + os.path.join(get_icon_dir(repodir, last_density), iconfilename), + os.path.join(get_icon_dir(repodir, density), iconfilename)) + + empty_densities.remove(density) # Copy from icons-mdpi to icons since mdpi is the baseline density shutil.copyfile(