add text to screenshots (wip)

This commit is contained in:
Vadim 2024-05-11 17:02:25 +02:00
parent 7dc155080b
commit e91da61238
4 changed files with 45 additions and 0 deletions

Binary file not shown.

Binary file not shown.

View file

@ -16,17 +16,25 @@ enum ScreenshotLayout {
iphone65inch(
size: (width: 1242, height: 2688),
contentPadding: (left: 150, top: 192, right: 150, bottom: 192),
titleFontPath: 'screenshots/assets/fonts/SF-Pro-Display-Bold.zip',
subtitleFontPath: 'screenshots/assets/fonts/SF-Pro-Display-Regular.zip',
),
iphone55inch(
size: (width: 1242, height: 2208),
contentPadding: (left: 150, top: 192, right: 150, bottom: 192),
titleFontPath: 'screenshots/assets/fonts/SF-Pro-Display-Bold.zip',
subtitleFontPath: 'screenshots/assets/fonts/SF-Pro-Display-Regular.zip',
);
final ({int height, int width}) size;
final ({int left, int top, int right, int bottom}) contentPadding;
final String titleFontPath;
final String subtitleFontPath;
const ScreenshotLayout({
required this.size,
required this.contentPadding,
required this.titleFontPath,
required this.subtitleFontPath,
});
}

View file

@ -102,4 +102,41 @@ extension ScreenshotImage on Image {
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,
);
}
}