Skip to content

Instantly share code, notes, and snippets.

@samtiffin
Created June 7, 2016 15:44
Show Gist options
  • Save samtiffin/aad995d5a1f0aa233a3e02fcf6afda8f to your computer and use it in GitHub Desktop.
Save samtiffin/aad995d5a1f0aa233a3e02fcf6afda8f to your computer and use it in GitHub Desktop.
Makes some favicons and shit like that
# coding=utf8
from PIL import Image
from os.path import join
icons = (
('android-icon-144x144.png', 144),
('android-icon-192x192.png', 192),
('android-icon-36x36.png', 36),
('android-icon-48x48.png', 48),
('android-icon-72x72.png', 72),
('android-icon-96x96.png', 96),
('apple-icon-114x114.png', 114),
('apple-icon-120x120.png', 120),
('apple-icon-144x144.png', 144),
('apple-icon-152x152.png', 152),
('apple-icon-180x180.png', 180),
('apple-icon-57x57.png', 57),
('apple-icon-60x60.png', 60),
('apple-icon-72x72.png', 72),
('apple-icon-76x76.png', 76),
('apple-icon-precomposed.png', 192),
('apple-icon.png', 192),
('favicon-16x16.png', 16),
('favicon-32x32.png', 32),
('favicon-96x96.png', 96),
('ms-icon-144x144.png', 144),
('ms-icon-150x150.png', 150),
('ms-icon-310x310.png', 310),
('ms-icon-70x70.png', 70),
)
in_file = r'favicon.png'
out_dir = 'out'
img = Image.open(in_file)
for name, size in icons:
print 'Generating {0} at {1}x{1}.'.format(name, size)
icon = img.copy()
icon.thumbnail((size, size,))
icon.save(join(out_dir, name))
favicon = img.copy()
print 'Generating favicon.ico.'
# This does some magic and saves out a proper icon file with various sizes
# Default sizes are:
# [(16, 16), (24, 24), (32, 32), (48, 48), (64, 64), (128, 128), (255, 255)]
# See: http://pillow.readthedocs.io/en/3.1.x/handbook/image-file-formats.html#ico
favicon.save(join(out_dir, 'favicon.ico'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment