Skip to content

Commit

Permalink
fix:Compatible with iPhone screenshot size.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Apr 11, 2023
1 parent b3da4be commit 599875a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
23 changes: 21 additions & 2 deletions packages/katana_cli/lib/command/store/screenshot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ const _resolution = <String, Map<String, _Size>>{
},
};

const _offset = <int, _Offset>{2732: _Offset(38, 32)};
const _offset = <int, _Offset>{
2732: _Offset(38, 32),
2556: _Offset(144, 48),
};
const _defaultOffset = _Offset(76, 48);

class _Offset {
Expand Down Expand Up @@ -77,6 +80,7 @@ class StoreScreenshotCliCommand extends CliCommand {
final colorCode = screenshot.get("color", "").trimString("#");
final orientation = screenshot.get("orientation", "");
final sourceDir = screenshot.get("source_dir", "");
final featureImageSourcePath = screenshot.get("feature_image", "");
if (exportDir.isEmpty) {
error(
"[store]->[screenshot]->[export_dir] is not found. Fill in the destination folder here.",
Expand Down Expand Up @@ -120,12 +124,27 @@ class StoreScreenshotCliCommand extends CliCommand {
}).toList();
label("Create a featured image.");
final featureImage = File("$exportDir/feature_image.png");
if (featureImageSourcePath.isNotEmpty) {
final featureImageSource = File(featureImageSourcePath);
if (featureImageSource.existsSync()) {
final source = decodeImage(featureImageSource.readAsBytesSync())!;
final resized = copyResize(source, width: 1024);
final cropped = copyCrop(
resized,
x: 0,
y: ((resized.height - 500) / 2.0).floor(),
width: resized.width,
height: 500,
);
featureImage.writeAsBytesSync(encodePng(cropped));
}
}
if (!featureImage.existsSync()) {
final image = Image(
width: 1024,
height: 500,
)..clear(color);
File("$exportDir/feature_image.png").writeAsBytesSync(encodePng(image));
featureImage.writeAsBytesSync(encodePng(image));
}
label("Create other screenshots.");
if (sources.isEmpty) {
Expand Down
1 change: 1 addition & 0 deletions packages/katana_cli/lib/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ store:
screenshot:
source_dir: document/screenshot
export_dir: document/store
feature_image: document/feature.png
orientation: portrait
color: '000000'
""";
Expand Down
4 changes: 2 additions & 2 deletions packages/katana_cli/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ packages:
dependency: "direct main"
description:
name: katana
sha256: f4e68a522ae23b317132990e9a3dc2d4cb0fd7155de081daf2cc52427d8b6c46
sha256: d2994914d6a1ec082f05cb753138e0a729370479dc7b47f51d4d6db4027e4087
url: "https://pub.dev"
source: hosted
version: "1.0.11"
version: "1.0.12"
lints:
dependency: "direct main"
description:
Expand Down

0 comments on commit 599875a

Please sign in to comment.