diff --git a/tool/generate_web_icons.dart b/tool/generate_web_icons.dart new file mode 100644 index 000000000..c9dfddf13 --- /dev/null +++ b/tool/generate_web_icons.dart @@ -0,0 +1,82 @@ +/* + * This file is part of wger Workout Manager . + * Copyright (c) 2026 wger Team + * + * wger Workout Manager is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +/// Regenerates the PWA icons and the favicon under web/ from the wger logo. +/// Run with: +/// dart run tool/generate_web_icons.dart +library; + +import 'dart:io'; + +import 'package:image/image.dart'; + +const _source = 'assets/images/logo-512.png'; +const _iconDir = 'web/icons'; +const _favicon = 'web/favicon.png'; + +const _sizes = [192, 512]; +const _faviconSize = 32; + +/// The brand blue the logo hexagon is filled with, so the hexagon blends into +/// the background and the result matches the Android launcher icon. +final _background = ColorRgb8(0x2a, 0x4c, 0x7d); + +/// Maskable icons get cropped to a launcher-chosen shape; only the centred +/// circle of 80% diameter is guaranteed to stay visible. Shrink the artwork so +/// the dumbbell clears that circle with a margin rather than touching it. +const _maskableScale = 0.82; + +void main() { + final source = decodePng(File(_source).readAsBytesSync()); + if (source == null) { + stderr.writeln('Could not decode $_source'); + exit(1); + } + + // The logo is transparent outside the hexagon, so flatten it onto the brand + // colour first: everything below works on an opaque, full-bleed icon. + final flattened = _onBackground(source.width, source.height); + compositeImage(flattened, source); + + for (final size in _sizes) { + _write('$_iconDir/Icon-$size.png', copyResize(flattened, width: size, height: size)); + + final artwork = (size * _maskableScale).round(); + final maskable = _onBackground(size, size); + final offset = ((size - artwork) / 2).round(); + compositeImage( + maskable, + copyResize(flattened, width: artwork, height: artwork), + dstX: offset, + dstY: offset, + ); + _write('$_iconDir/Icon-maskable-$size.png', maskable); + } + + _write(_favicon, copyResize(flattened, width: _faviconSize, height: _faviconSize)); +} + +/// An opaque [width] x [height] canvas filled with the brand colour. Alpha is +/// dropped because the icons are always composited on their own background. +Image _onBackground(int width, int height) => + Image(width: width, height: height, numChannels: 3)..clear(_background); + +void _write(String path, Image image) { + File(path).writeAsBytesSync(encodePng(image)); + stdout.writeln('wrote $path (${image.width}x${image.height})'); +} diff --git a/web/favicon.png b/web/favicon.png index f1013f033..256e993e3 100644 Binary files a/web/favicon.png and b/web/favicon.png differ diff --git a/web/icons/Icon-192.png b/web/icons/Icon-192.png index b749bfef0..37d5b4620 100644 Binary files a/web/icons/Icon-192.png and b/web/icons/Icon-192.png differ diff --git a/web/icons/Icon-512.png b/web/icons/Icon-512.png index 88cfd48df..6491fa884 100644 Binary files a/web/icons/Icon-512.png and b/web/icons/Icon-512.png differ diff --git a/web/icons/Icon-maskable-192.png b/web/icons/Icon-maskable-192.png new file mode 100644 index 000000000..286963a83 Binary files /dev/null and b/web/icons/Icon-maskable-192.png differ diff --git a/web/icons/Icon-maskable-512.png b/web/icons/Icon-maskable-512.png new file mode 100644 index 000000000..82a1bc745 Binary files /dev/null and b/web/icons/Icon-maskable-512.png differ diff --git a/web/index.html b/web/index.html index 7b43330fd..17abbe9ca 100644 --- a/web/index.html +++ b/web/index.html @@ -18,7 +18,7 @@ - + diff --git a/web/manifest.json b/web/manifest.json index 0e3090fe1..2576ed207 100644 --- a/web/manifest.json +++ b/web/manifest.json @@ -3,9 +3,9 @@ "short_name": "wger", "start_url": ".", "display": "standalone", - "background_color": "#0175C2", - "theme_color": "#0175C2", - "description": "A new Flutter project.", + "background_color": "#ffffff", + "theme_color": "#2a4c7d", + "description": "Fitness/workout, nutrition and weight tracker", "orientation": "portrait-primary", "prefer_related_applications": false, "icons": [ @@ -18,6 +18,18 @@ "src": "icons/Icon-512.png", "sizes": "512x512", "type": "image/png" + }, + { + "src": "icons/Icon-maskable-192.png", + "sizes": "192x192", + "type": "image/png", + "purpose": "maskable" + }, + { + "src": "icons/Icon-maskable-512.png", + "sizes": "512x512", + "type": "image/png", + "purpose": "maskable" } ] }