Calibrate badge positioning and add debug guides in machine_1

- Adjust badge center calculations for improved alignment based on asset layout.
- Temporarily disable optical nudge calibration for badge centering.
- Add debug crosshair overlays to validate badge and text anchor points during rendering.
This commit is contained in:
Jeppe Bundgaard
2026-01-28 16:46:04 +01:00
parent 220eda5cb5
commit ab7bd4c2da
@@ -90,22 +90,26 @@ class machine_1 extends dynamicimages_image
$badgeDiameter = 0.25 * min($imgW, $imgH);
$badgeRadius = $badgeDiameter / 2.0;
// Center of the badge is at the top-right corner, inset by its radius
$cx = $imgW - $badgeRadius; // circle center X
$cy = $badgeRadius; // circle center Y
// Center of the badge is near the top-right corner; apply inner inset to match actual asset layout
$centerXNudgeIn = 0.50 * $badgeDiameter; // move inward from right edge (~43% of diameter)
$centerYNudgeIn = 0.50 * $badgeDiameter; // move downward from top edge (~43% of diameter)
$cx = $imgW - $badgeRadius - $centerXNudgeIn; // adjusted circle center X
$cy = $badgeRadius + $centerYNudgeIn; // adjusted circle center Y
// We use center/center alignment and offset from the image center to the badge center
$xOffset = (int)round($cx - ($imgW / 2.0));
$yOffset = (int)round($cy - ($imgH / 2.0));
$baseCenterXOffset = (int)round($cx - ($imgW / 2.0));
$baseCenterYOffset = (int)round($cy - ($imgH / 2.0));
$xOffset = $baseCenterXOffset;
$yOffset = $baseCenterYOffset;
// Optical centering tweak (calibration v3):
// Feedback: still a bit to the right and too high (high-right).
// Increase nudge: shift left by ~4% and down by ~3% of badge diameter.
$xNudge = 0.04 * $badgeDiameter; // left
$yNudge = 0.03 * $badgeDiameter; // down
// Temporarily disable optical nudge while calibrating true badge center
$xNudge = 0.00 * $badgeDiameter;
$yNudge = 0.00 * $badgeDiameter;
$xOffset -= (int)round($xNudge);
$yOffset += (int)round($yNudge);
// (Debug guides will be drawn after the numeral so they remain visible)
// Compute a dynamic font size that fits up to 2 digits comfortably inside the badge
// Target occupied size inside the circle (padding from edges)
$targetFrac = 0.72; // 72% of diameter for both width and height
@@ -166,6 +170,33 @@ class machine_1 extends dynamicimages_image
'align' => 'center',
'valign' => 'center',
]);
// DEBUG guides: draw small crosshairs to verify target points (will be removed after calibration)
// 1) Red '+' at the adjusted mathematical badge center (no optical nudge)
// 2) Yellow '+' at the final text anchor after optical nudge
try {
$guideFontSize = (int)max(8, round($badgeDiameter * 0.22));
$buttonAsset->addTextOverlay('+', [
'font_size' => $guideFontSize,
'font_color' => '#FF0000', // red
'font_path' => $font,
'x_offset' => $baseCenterXOffset,
'y_offset' => $baseCenterYOffset,
'align' => 'center',
'valign' => 'center',
]);
$buttonAsset->addTextOverlay('+', [
'font_size' => $guideFontSize,
'font_color' => '#FFD400', // yellow
'font_path' => $font,
'x_offset' => $xOffset,
'y_offset' => $yOffset,
'align' => 'center',
'valign' => 'center',
]);
} catch (\Throwable $e) {
// Ignore debug overlay errors
}
return $buttonAsset;
}