in make_manifest.py [0:0]
def get_best_icon(images):
image_url = None
image_width = 0
for image in images:
url = fix_url(image.get('href'))
width = None
sizes = image.get('sizes')
if sizes:
try:
width = int(sizes.split('x')[0])
except:
pass
if width is None:
try:
response = requests.get(url, headers={'User-agent': FIREFOX_UA}, timeout=60)
# If it is an SVG, then return this as the best icon because SVG images are scalable,
# can be printed with high quality at any resolution and SVG graphics do NOT
# lose any quality if they are zoomed or resized.
if response.headers.get('Content-Type') == 'image/svg+xml':
# Firefox doesn't support masked icons yet.
if 'mask' not in image:
# If it is not then we want it. We are done here.
return (url, SVG_ICON_WIDTH)
else:
logging.info(f'SVG icon "{image}" is masked')
continue
with Image.open(BytesIO(response.content)) as img:
width, height = img.size
if width != height:
logging.info(f'icon shape "{width}*{height}" is not square')
width = min(width, height)
except Exception as e:
logging.info(f'Exception: "{str(e)}" fetching (or opening) icon {url}')
pass
if width and width > image_width:
image_url = url
image_width = width
return (image_url, image_width)