mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-22 07:20:39 +00:00
store raw screenshots
This commit is contained in:
parent
3e16e91f02
commit
892c061633
3 changed files with 10 additions and 126 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -63,4 +63,4 @@ ios/Runner/GoogleService-Info.plist
|
|||
coverage/
|
||||
test/coverage_helper_test.dart
|
||||
**/failures/*.png
|
||||
screenshots/generated/
|
||||
screenshots/generated/raw/
|
|
@ -15,6 +15,7 @@ class ScreenshotArgs {
|
|||
required this.isDark,
|
||||
});
|
||||
|
||||
String toPathRaw() => 'screenshots/generated/raw/$platformFolder/$deviceName/$name.png';
|
||||
String toPath() => 'screenshots/generated/$platformFolder/$deviceName/$name.png';
|
||||
|
||||
@override
|
||||
|
|
|
@ -4,139 +4,22 @@ import 'dart:typed_data';
|
|||
import 'package:image/image.dart';
|
||||
import 'package:integration_test/integration_test_driver_extended.dart';
|
||||
|
||||
import '../screenshots/devices_config.dart';
|
||||
import '../screenshots/screenshot_args.dart';
|
||||
import '../screenshots/screenshot_config.dart';
|
||||
import 'utils/grant_camera_permission.dart';
|
||||
import '../screenshots/convert_to_store_screenshot.dart';
|
||||
import '../screenshots/models/screenshot_args.dart';
|
||||
import '../screenshots/models/screenshot_layout.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
await grantCameraPermission();
|
||||
await integrationDriver(
|
||||
onScreenshot: (name, bytes, [_]) async {
|
||||
final screenshotArgs = ScreenshotArgs.fromString(name);
|
||||
final backgroundColor = ColorRgba8(
|
||||
screenshotArgs.backgroundColor.r,
|
||||
screenshotArgs.backgroundColor.g,
|
||||
screenshotArgs.backgroundColor.b,
|
||||
screenshotArgs.backgroundColor.a,
|
||||
final file = await File(screenshotArgs.toPathRaw()).create(recursive: true);
|
||||
final screenshot = decodePng(Uint8List.fromList(bytes))!.convertToStoreScreenshot(
|
||||
args: screenshotArgs,
|
||||
layout: ScreenshotLayout.iphone65inch,
|
||||
);
|
||||
final platform =
|
||||
screenshotArgs.platformFolder == 'ios' ? ScreenshotDevicePlatform.ios : ScreenshotDevicePlatform.ios;
|
||||
final deviceName = screenshotArgs.deviceName;
|
||||
final file = await File(screenshotArgs.toPath()).create(recursive: true);
|
||||
|
||||
// switch (platform) {
|
||||
// case ScreenshotDevicePlatform.ios:
|
||||
// final device = screenshotDevicesIos.firstWhere(
|
||||
// (device) => device.name == deviceName,
|
||||
// orElse: () => ScreenshotDevice(name: '', platform: platform),
|
||||
// );
|
||||
// Image screenshot = decodePng(Uint8List.fromList(bytes))!;
|
||||
// screenshot = screenshot.addSystemOverlay(device, isDark: screenshotArgs.isDark);
|
||||
// screenshot = screenshot.addDeviceFrame(device, backgroundColor);
|
||||
// file.writeAsBytesSync(encodePng(screenshot));
|
||||
// case ScreenshotDevicePlatform.android:
|
||||
// file.writeAsBytesSync(bytes);
|
||||
// }
|
||||
|
||||
file.writeAsBytesSync(bytes);
|
||||
file.writeAsBytesSync(encodePng(screenshot));
|
||||
return true;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
extension ScreenshotImage on Image {
|
||||
Image addSystemOverlay(ScreenshotDevice device, {required bool isDark}) {
|
||||
final path = isDark ? device.systemOverlayPathDark : device.systemOverlayPathLight;
|
||||
final statusBar = copyResize(
|
||||
decodePng(File(path).readAsBytesSync())!,
|
||||
width: width,
|
||||
);
|
||||
return compositeImage(this, statusBar);
|
||||
}
|
||||
|
||||
Image addDeviceFrame(ScreenshotDevice device, Color backgroundColor) {
|
||||
final screenshotRounded = copyCrop(
|
||||
this,
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: width,
|
||||
height: height,
|
||||
);
|
||||
|
||||
final frame = decodePng(File(device.deviceFramePath).readAsBytesSync())!;
|
||||
final expandedScreenshot = copyExpandCanvas(
|
||||
copyExpandCanvas(
|
||||
screenshotRounded,
|
||||
newWidth: screenshotRounded.width + device.screenshotFrameOffset.dx,
|
||||
newHeight: screenshotRounded.height + device.screenshotFrameOffset.dy,
|
||||
position: ExpandCanvasPosition.bottomRight,
|
||||
backgroundColor: backgroundColor,
|
||||
),
|
||||
newWidth: frame.width,
|
||||
newHeight: frame.height,
|
||||
position: ExpandCanvasPosition.topLeft,
|
||||
backgroundColor: backgroundColor,
|
||||
);
|
||||
|
||||
return compositeImage(expandedScreenshot, frame);
|
||||
}
|
||||
|
||||
Image applyLayout(ScreenshotLayout layout) {
|
||||
final scaledScreenshot = copyResize(
|
||||
this,
|
||||
width: layout.size.width - (layout.contentPadding.left + layout.contentPadding.right),
|
||||
);
|
||||
|
||||
return copyExpandCanvas(
|
||||
copyExpandCanvas(
|
||||
scaledScreenshot,
|
||||
newWidth: scaledScreenshot.width + layout.contentPadding.right,
|
||||
newHeight: scaledScreenshot.height + layout.contentPadding.bottom,
|
||||
position: ExpandCanvasPosition.topLeft,
|
||||
backgroundColor: getPixel(0, 0),
|
||||
),
|
||||
newWidth: layout.size.width,
|
||||
newHeight: layout.size.height,
|
||||
position: ExpandCanvasPosition.bottomRight,
|
||||
backgroundColor: getPixel(0, 0),
|
||||
);
|
||||
}
|
||||
|
||||
Image addText(ScreenshotLayout layout, String title, String subtitle) {
|
||||
final titleFont = BitmapFont.fromZip(File(layout.titleFontPath).readAsBytesSync());
|
||||
final subtitleFont = BitmapFont.fromZip(File(layout.subtitleFontPath).readAsBytesSync());
|
||||
final textImage = fill(
|
||||
Image(
|
||||
height: titleFont.lineHeight + 36 + subtitleFont.lineHeight * 2,
|
||||
width: layout.size.width - (layout.contentPadding.left + layout.contentPadding.right),
|
||||
),
|
||||
color: getPixel(0, 0),
|
||||
);
|
||||
|
||||
drawString(
|
||||
textImage,
|
||||
title,
|
||||
font: titleFont,
|
||||
y: 0,
|
||||
);
|
||||
|
||||
int subtitleDy = titleFont.lineHeight + 36;
|
||||
subtitle.split('\n').forEach((line) {
|
||||
drawString(
|
||||
textImage,
|
||||
line,
|
||||
font: subtitleFont,
|
||||
y: subtitleDy,
|
||||
);
|
||||
subtitleDy += subtitleFont.lineHeight;
|
||||
});
|
||||
|
||||
return compositeImage(
|
||||
this,
|
||||
textImage,
|
||||
dstX: layout.contentPadding.left,
|
||||
dstY: layout.contentPadding.top,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue