scale device frame (wip)

This commit is contained in:
Vadim 2024-05-11 16:07:03 +02:00
parent 0c6519efa1
commit 7dc155080b
2 changed files with 54 additions and 0 deletions

View file

@ -0,0 +1,32 @@
import 'dart:convert';
class ScreenshotConfig {
final String title;
final String subtitle;
final String screenshotPath;
const ScreenshotConfig({
required this.title,
required this.subtitle,
required this.screenshotPath,
});
}
enum ScreenshotLayout {
iphone65inch(
size: (width: 1242, height: 2688),
contentPadding: (left: 150, top: 192, right: 150, bottom: 192),
),
iphone55inch(
size: (width: 1242, height: 2208),
contentPadding: (left: 150, top: 192, right: 150, bottom: 192),
);
final ({int height, int width}) size;
final ({int left, int top, int right, int bottom}) contentPadding;
const ScreenshotLayout({
required this.size,
required this.contentPadding,
});
}

View file

@ -6,6 +6,7 @@ import 'package:integration_test/integration_test_driver_extended.dart';
import '../screenshots/devices_config.dart'; import '../screenshots/devices_config.dart';
import '../screenshots/screenshot_args.dart'; import '../screenshots/screenshot_args.dart';
import '../screenshots/screenshot_config.dart';
import 'utils/grant_camera_permission.dart'; import 'utils/grant_camera_permission.dart';
Future<void> main() async { Future<void> main() async {
@ -80,4 +81,25 @@ extension ScreenshotImage on Image {
return compositeImage(expandedScreenshot, frame); 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),
);
}
} }