Remove the alpha channel from the screenshots

This commit is contained in:
Roland Geider
2026-08-20 22:20:25 +02:00
parent 79a8c3e306
commit 558a07d0da
3 changed files with 40 additions and 4 deletions

View File

@@ -157,10 +157,10 @@ packages:
dependency: transitive
description:
name: camera_android_camerax
sha256: "294b02ae027ad9edc98414a25f5e958d2dc6c65e9f102f21e2b36f0f558751eb"
sha256: "47aa7c2963ceb8db4fc3dfbba0f9195da3741f3d11e80f0e29472d46bf4c2e66"
url: "https://pub.dev"
source: hosted
version: "0.7.4+4"
version: "0.7.4+6"
camera_avfoundation:
dependency: transitive
description:
@@ -801,7 +801,7 @@ packages:
source: hosted
version: "4.1.2"
image:
dependency: transitive
dependency: "direct dev"
description:
name: image
sha256: "6300175e00616bbc832e2fc91bfa4d776af5402c81c7151bee6905bb08473c52"

View File

@@ -107,6 +107,8 @@ dev_dependencies:
flutter_lints: ^6.0.0
flutter_native_splash: ^2.4.8
freezed: ^3.2.0
# Used to strip the alpha channel from the generated store screenshots
image: ^4.9.1
json_serializable: ^6.14.1
mockito: ^5.6.4
network_image_mock: ^2.1.1

View File

@@ -1,7 +1,27 @@
/*
* This file is part of wger Workout Manager <https://github.com/wger-project>.
* 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 <http://www.gnu.org/licenses/>.
*/
// ignore_for_file: avoid_print
import 'dart:io';
import 'dart:typed_data';
import 'package:image/image.dart' as img;
import 'package:integration_test/integration_test_driver_extended.dart';
// cf. https://dev.to/mjablecnik/take-screenshot-during-flutter-integration-tests-435k
@@ -10,7 +30,7 @@ Future<void> main() async {
await integrationDriver(
onScreenshot: (String screenshotName, List<int> screenshotBytes, [_]) async {
final File image = await File(screenshotName).create(recursive: true);
image.writeAsBytesSync(screenshotBytes);
image.writeAsBytesSync(_withoutAlpha(screenshotBytes));
return true;
},
);
@@ -18,3 +38,17 @@ Future<void> main() async {
print('An error occurred: $e');
}
}
/// Re-encodes a PNG as opaque 8 bit RGB
///
/// The App Store rejects screenshots with an alpha channel. Returns the
/// input unchanged if it can't be decoded.
List<int> _withoutAlpha(List<int> bytes) {
final decoded = img.decodePng(Uint8List.fromList(bytes));
if (decoded == null) {
print('Could not decode the screenshot, writing it out unchanged');
return bytes;
}
return img.encodePng(decoded.convert(format: img.Format.uint8, numChannels: 3));
}