afterbefore 0.1.13 → 0.1.14

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.
package/dist/index.js CHANGED
@@ -1644,34 +1644,37 @@ async function captureRoutes(tasks, beforeUrl, afterUrl, outputDir, options) {
1644
1644
 
1645
1645
  // src/stages/compare.ts
1646
1646
  import { join as join7, dirname as dirname2 } from "path";
1647
- import { readFileSync as readFileSync5, unlinkSync } from "fs";
1647
+ import { unlinkSync } from "fs";
1648
1648
  import { ODiffServer } from "odiff-bin";
1649
1649
  import sharp from "sharp";
1650
- function readPngSize(path) {
1651
- const buf = readFileSync5(path);
1652
- return { width: buf.readUInt32BE(16), height: buf.readUInt32BE(20) };
1650
+ async function trimImage(path) {
1651
+ const { data, info } = await sharp(path).trim({ threshold: 50 }).toBuffer({ resolveWithObject: true });
1652
+ return { data, width: info.width, height: info.height };
1653
1653
  }
1654
1654
  async function generateComposite(beforePath, afterPath, outputPath, bgColor) {
1655
- const beforeSize = readPngSize(beforePath);
1656
- const afterSize = readPngSize(afterPath);
1657
- const imgW = Math.max(beforeSize.width, afterSize.width);
1658
- const imgH = Math.max(beforeSize.height, afterSize.height);
1659
- const PADDING = 120;
1660
- const GAP = 80;
1655
+ const [beforeTrimmed, afterTrimmed] = await Promise.all([
1656
+ trimImage(beforePath),
1657
+ trimImage(afterPath)
1658
+ ]);
1659
+ const imgW = Math.max(beforeTrimmed.width, afterTrimmed.width);
1660
+ const imgH = Math.max(beforeTrimmed.height, afterTrimmed.height);
1661
+ const PADDING = 40;
1662
+ const GAP = 40;
1661
1663
  const LABEL_H = 70;
1662
1664
  const canvasW = Math.max(600, Math.min(2400, imgW * 2 + GAP + PADDING * 2));
1663
1665
  const canvasH = Math.max(300, Math.min(2400, imgH + LABEL_H + PADDING * 2));
1664
1666
  const maxImgH = canvasH - PADDING * 2 - LABEL_H;
1665
1667
  const colW = Math.floor((canvasW - PADDING * 2 - GAP) / 2);
1666
- const [beforeBuf, afterBuf] = await Promise.all([
1667
- sharp(beforePath).resize(colW, maxImgH, { fit: "inside" }).toBuffer({ resolveWithObject: true }),
1668
- sharp(afterPath).resize(colW, maxImgH, { fit: "inside" }).toBuffer({ resolveWithObject: true })
1669
- ]);
1668
+ const [beforeBuf, afterBuf] = await Promise.all(
1669
+ [beforeTrimmed, afterTrimmed].map(async (trimmed) => {
1670
+ return await sharp(trimmed.data).resize(colW, maxImgH, { fit: "inside" }).toBuffer({ resolveWithObject: true });
1671
+ })
1672
+ );
1670
1673
  const beforeLeft = PADDING + Math.floor((colW - beforeBuf.info.width) / 2);
1671
1674
  const beforeTop = PADDING + Math.floor((maxImgH - beforeBuf.info.height) / 2);
1672
1675
  const afterLeft = PADDING + colW + GAP + Math.floor((colW - afterBuf.info.width) / 2);
1673
1676
  const afterTop = PADDING + Math.floor((maxImgH - afterBuf.info.height) / 2);
1674
- const labelY = PADDING + maxImgH + 50;
1677
+ const labelY = PADDING + maxImgH + 20;
1675
1678
  const beforeLabelX = PADDING + Math.floor(colW / 2);
1676
1679
  const afterLabelX = PADDING + colW + GAP + Math.floor(colW / 2);
1677
1680
  const labelSvg = Buffer.from(
@@ -1926,7 +1929,7 @@ async function runPipeline(options) {
1926
1929
  const outputDir = resolve4(cwd, output, sessionName);
1927
1930
  const startTime = Date.now();
1928
1931
  try {
1929
- const version = true ? "0.1.13" : "dev";
1932
+ const version = true ? "0.1.14" : "dev";
1930
1933
  console.log(`
1931
1934
  afterbefore v${version} \xB7 Comparing against ${base}
1932
1935
  `);