device-shots 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +32 -19
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -142,7 +142,7 @@ function getAndroidScreenSize(width, height) {
142
142
  const longer = Math.max(width, height);
143
143
  const ratio = longer / shorter;
144
144
  if (ratio >= 1.7) return "phone";
145
- if (shorter >= 1800) return "tablet-10";
145
+ if (shorter >= 1500) return "tablet-10";
146
146
  if (shorter >= 1200) return "tablet-7";
147
147
  return "phone";
148
148
  }
@@ -469,6 +469,9 @@ async function frameAndroidScreenshot(inputPath, outputPath) {
469
469
  if (!await commandExists("magick")) {
470
470
  throw new Error("ImageMagick is required for Android framing. Install with: brew install imagemagick");
471
471
  }
472
+ const { unlinkSync: unlinkSync2 } = await import("fs");
473
+ const { join: join5 } = await import("path");
474
+ const { tmpdir: tmpdir2 } = await import("os");
472
475
  const { stdout: identify } = await run("magick", [
473
476
  "identify",
474
477
  "-format",
@@ -483,23 +486,27 @@ async function frameAndroidScreenshot(inputPath, outputPath) {
483
486
  const radius = Math.round(width * 0.04);
484
487
  const totalW = width + padding * 2;
485
488
  const totalH = height + padding * 2;
489
+ const uid = Date.now();
490
+ const tmpMask = join5(tmpdir2(), `ds-mask-${uid}.png`);
491
+ const tmpRounded = join5(tmpdir2(), `ds-rounded-${uid}.png`);
486
492
  try {
487
- const tmpRounded = inputPath.replace(".png", "_rounded_tmp.png");
493
+ await runOrFail("magick", [
494
+ "-size",
495
+ `${width}x${height}`,
496
+ "xc:black",
497
+ "-fill",
498
+ "white",
499
+ "-draw",
500
+ `roundrectangle 0,0 ${width - 1},${height - 1} ${radius},${radius}`,
501
+ tmpMask
502
+ ]);
488
503
  await runOrFail("magick", [
489
504
  inputPath,
505
+ tmpMask,
490
506
  "-alpha",
491
- "set",
492
- "(",
493
- "+clone",
494
- "-alpha",
495
- "extract",
496
- "-draw",
497
- `fill black color 0,0 reset`,
498
- "-draw",
499
- `fill white roundrectangle 0,0 ${width - 1},${height - 1} ${radius},${radius}`,
500
- ")",
507
+ "off",
501
508
  "-compose",
502
- "DstIn",
509
+ "CopyOpacity",
503
510
  "-composite",
504
511
  tmpRounded
505
512
  ]);
@@ -507,8 +514,10 @@ async function frameAndroidScreenshot(inputPath, outputPath) {
507
514
  "-size",
508
515
  `${totalW}x${totalH}`,
509
516
  "xc:none",
517
+ "-fill",
518
+ "black",
510
519
  "-draw",
511
- `fill black roundrectangle 0,0 ${totalW - 1},${totalH - 1} ${radius},${radius}`,
520
+ `roundrectangle 0,0 ${totalW - 1},${totalH - 1} ${radius},${radius}`,
512
521
  tmpRounded,
513
522
  "-gravity",
514
523
  "center",
@@ -517,14 +526,18 @@ async function frameAndroidScreenshot(inputPath, outputPath) {
517
526
  "-composite",
518
527
  outputPath
519
528
  ]);
529
+ return true;
530
+ } catch {
531
+ return false;
532
+ } finally {
533
+ try {
534
+ unlinkSync2(tmpMask);
535
+ } catch {
536
+ }
520
537
  try {
521
- const { unlinkSync: unlinkSync2 } = await import("fs");
522
538
  unlinkSync2(tmpRounded);
523
539
  } catch {
524
540
  }
525
- return true;
526
- } catch {
527
- return false;
528
541
  }
529
542
  }
530
543
  async function frameAllIosScreenshots(screenshotsDir, force = false) {
@@ -829,7 +842,7 @@ async function frameCommand(dir, options) {
829
842
  var program = new Command();
830
843
  program.name("device-shots").description(
831
844
  "Capture and frame mobile app screenshots from iOS simulators and Android emulators"
832
- ).version("0.5.0");
845
+ ).version("0.5.1");
833
846
  program.command("capture").description("Capture screenshots from running devices").argument("[name]", "Screenshot name").option("-b, --bundle-id <id>", "App bundle ID").option("-o, --output <dir>", "Output directory").option("-p, --platform <platform>", "ios, android, or both").option("--no-frame", "Skip framing after capture").option("--time <time>", "Status bar time", "9:41").action(async (name, opts) => {
834
847
  await captureCommand({ name, ...opts });
835
848
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "device-shots",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Capture and frame mobile app screenshots from iOS simulators and Android emulators",
5
5
  "type": "module",
6
6
  "bin": {