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/cli.js +20 -17
- package/dist/cli.js.map +1 -1
- package/dist/index.js +19 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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 {
|
|
1647
|
+
import { unlinkSync } from "fs";
|
|
1648
1648
|
import { ODiffServer } from "odiff-bin";
|
|
1649
1649
|
import sharp from "sharp";
|
|
1650
|
-
function
|
|
1651
|
-
const
|
|
1652
|
-
return { width:
|
|
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
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
const
|
|
1660
|
-
const
|
|
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
|
-
|
|
1668
|
-
|
|
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 +
|
|
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.
|
|
1932
|
+
const version = true ? "0.1.14" : "dev";
|
|
1930
1933
|
console.log(`
|
|
1931
1934
|
afterbefore v${version} \xB7 Comparing against ${base}
|
|
1932
1935
|
`);
|