mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
svg logo #282
This commit is contained in:
parent
fcd248c558
commit
5b8d4642ca
3 changed files with 29 additions and 26 deletions
|
@ -13,9 +13,8 @@ from app.models import Community, User
|
|||
class SiteProfileForm(FlaskForm):
|
||||
name = StringField(_l('Site Name'))
|
||||
description = StringField(_l('Tagline'))
|
||||
icon = FileField(_l('Icon'), validators=[
|
||||
FileAllowed(['jpg', 'jpeg', 'png', 'webp'], 'Images only!')
|
||||
], render_kw={'accept': 'image/*'})
|
||||
icon = FileField(_l('Icon'), validators=[FileAllowed(['jpg', 'jpeg', 'png', 'webp', 'svg'], 'Images only!')],
|
||||
render_kw={'accept': 'image/*'})
|
||||
sidebar = TextAreaField(_l('Sidebar'))
|
||||
about = TextAreaField(_l('About'))
|
||||
announcement = TextAreaField(_l('Announcement at top of home page'))
|
||||
|
|
|
@ -60,7 +60,7 @@ def admin_site():
|
|||
# Save site icon
|
||||
uploaded_icon = request.files['icon']
|
||||
if uploaded_icon and uploaded_icon.filename != '':
|
||||
allowed_extensions = ['.gif', '.jpg', '.jpeg', '.png', '.webp']
|
||||
allowed_extensions = ['.gif', '.jpg', '.jpeg', '.png', '.webp', '.svg']
|
||||
file_ext = os.path.splitext(uploaded_icon.filename)[1]
|
||||
if file_ext.lower() not in allowed_extensions:
|
||||
abort(400)
|
||||
|
@ -80,31 +80,35 @@ def admin_site():
|
|||
# Save logo file
|
||||
base_filename = f'logo_{gibberish(5)}'
|
||||
uploaded_icon.save(f'{directory}/{base_filename}{file_ext}')
|
||||
img = Image.open(f'{directory}/{base_filename}{file_ext}')
|
||||
if img.width > 100:
|
||||
img.thumbnail((100, 100))
|
||||
img.save(f'{directory}/{base_filename}_100{file_ext}')
|
||||
site.logo = f'/static/media/{base_filename}_100{file_ext}'
|
||||
delete_original = True
|
||||
else:
|
||||
site.logo = f'/static/media/{base_filename}{file_ext}'
|
||||
if file_ext == '.svg':
|
||||
delete_original = False
|
||||
site.logo = site.logo_152 = site.logo_32 = site.logo_16 = f'/static/media/{base_filename}{file_ext}'
|
||||
else:
|
||||
img = Image.open(f'{directory}/{base_filename}{file_ext}')
|
||||
if img.width > 100:
|
||||
img.thumbnail((100, 100))
|
||||
img.save(f'{directory}/{base_filename}_100{file_ext}')
|
||||
site.logo = f'/static/media/{base_filename}_100{file_ext}'
|
||||
delete_original = True
|
||||
else:
|
||||
site.logo = f'/static/media/{base_filename}{file_ext}'
|
||||
delete_original = False
|
||||
|
||||
# Save multiple copies of the logo - different sizes
|
||||
img = Image.open(f'{directory}/{base_filename}{file_ext}')
|
||||
img.thumbnail((152, 152))
|
||||
img.save(f'{directory}/{base_filename}_152{file_ext}')
|
||||
site.logo_152 = f'/static/media/{base_filename}_152{file_ext}'
|
||||
# Save multiple copies of the logo - different sizes
|
||||
img = Image.open(f'{directory}/{base_filename}{file_ext}')
|
||||
img.thumbnail((152, 152))
|
||||
img.save(f'{directory}/{base_filename}_152{file_ext}')
|
||||
site.logo_152 = f'/static/media/{base_filename}_152{file_ext}'
|
||||
|
||||
img = Image.open(f'{directory}/{base_filename}{file_ext}')
|
||||
img.thumbnail((32, 32))
|
||||
img.save(f'{directory}/{base_filename}_32{file_ext}')
|
||||
site.logo_32 = f'/static/media/{base_filename}_32{file_ext}'
|
||||
img = Image.open(f'{directory}/{base_filename}{file_ext}')
|
||||
img.thumbnail((32, 32))
|
||||
img.save(f'{directory}/{base_filename}_32{file_ext}')
|
||||
site.logo_32 = f'/static/media/{base_filename}_32{file_ext}'
|
||||
|
||||
img = Image.open(f'{directory}/{base_filename}{file_ext}')
|
||||
img.thumbnail((16, 16))
|
||||
img.save(f'{directory}/{base_filename}_16{file_ext}')
|
||||
site.logo_16 = f'/static/media/{base_filename}_16{file_ext}'
|
||||
img = Image.open(f'{directory}/{base_filename}{file_ext}')
|
||||
img.thumbnail((16, 16))
|
||||
img.save(f'{directory}/{base_filename}_16{file_ext}')
|
||||
site.logo_16 = f'/static/media/{base_filename}_16{file_ext}'
|
||||
|
||||
if delete_original:
|
||||
os.unlink(f'app/static/media/{base_filename}{file_ext}')
|
||||
|
|
|
@ -102,7 +102,7 @@
|
|||
{% block navbar -%}
|
||||
<div class="navbar navbar-expand-lg sticky-md-top">
|
||||
<div class="{{ 'container-lg' if post_layout != 'masonry_wide' else 'container-fluid' }}" role="banner">
|
||||
<a class="navbar-brand" href="/">{% if not low_bandwidth %}<img src="{{ g.site.logo if g.site.logo else '/static/images/logo2.png' }}" alt="Logo" width="50" height="50" />{% endif %}{{ g.site.name }}</a>
|
||||
<a class="navbar-brand" href="/">{% if not low_bandwidth %}<img src="{{ g.site.logo if g.site.logo else '/static/images/logo.svg' }}" alt="Logo" width="50" height="50" />{% endif %}{{ g.site.name }}</a>
|
||||
{% if current_user.is_authenticated -%}
|
||||
<a class="nav-link d-lg-none" href="/notifications" aria-label="{{ _('Notifications') }}">
|
||||
{% if current_user.unread_notifications -%}
|
||||
|
|
Loading…
Add table
Reference in a new issue