diff --git a/services/nginx/app/modules/dynamicimages/assets/machine_1/machine_1_button_highlighted_blue.png b/services/nginx/app/modules/dynamicimages/assets/machine_1/machine_1_button_highlighted_blue.png index babd9ff7..b464de90 100644 Binary files a/services/nginx/app/modules/dynamicimages/assets/machine_1/machine_1_button_highlighted_blue.png and b/services/nginx/app/modules/dynamicimages/assets/machine_1/machine_1_button_highlighted_blue.png differ diff --git a/services/nginx/app/modules/dynamicimages/assets/machine_1/machine_1_button_highlighted_completed_grey.png b/services/nginx/app/modules/dynamicimages/assets/machine_1/machine_1_button_highlighted_completed_grey.png index e1781178..a09629b1 100644 Binary files a/services/nginx/app/modules/dynamicimages/assets/machine_1/machine_1_button_highlighted_completed_grey.png and b/services/nginx/app/modules/dynamicimages/assets/machine_1/machine_1_button_highlighted_completed_grey.png differ diff --git a/services/nginx/app/modules/dynamicimages/assets/machine_1/machine_1_button_highlighted_grey.png b/services/nginx/app/modules/dynamicimages/assets/machine_1/machine_1_button_highlighted_grey.png index 74779b2a..e0a685e5 100644 Binary files a/services/nginx/app/modules/dynamicimages/assets/machine_1/machine_1_button_highlighted_grey.png and b/services/nginx/app/modules/dynamicimages/assets/machine_1/machine_1_button_highlighted_grey.png differ diff --git a/services/nginx/app/modules/dynamicimages/images/machine_1.php b/services/nginx/app/modules/dynamicimages/images/machine_1.php index 27b3339d..bb4e323a 100644 --- a/services/nginx/app/modules/dynamicimages/images/machine_1.php +++ b/services/nginx/app/modules/dynamicimages/images/machine_1.php @@ -42,6 +42,7 @@ class machine_1 extends dynamicimages_image // Config public bool $only_generate_current_step = false; // If true, only generate the current step button highlights + /** * @throws \Exception */ @@ -75,6 +76,17 @@ class machine_1 extends dynamicimages_image $this->drawHighlightedButtons(); $this->drawAsset($this->getAsset(self::IMAGE_POWER_BUTTON), 0, 0); $this->drawHighlightedStartButton(); + $this->drawCropOutLine(); + } + + public function drawCropOutLine(): void + { + $x1 = 0; + $y1 = 3750; + $x2 = 6000; + $y2 = 3750; + + $this->drawLine($x1, $y1, $x2, $y2, self::IMAGE_CROP_LINE); } public function getHighlightedAssetName(): string @@ -128,8 +140,86 @@ class machine_1 extends dynamicimages_image $tmp->clearMemoryImage(); } } - + public function drawStepCounterOnButton(dynamicimages_asset $buttonAsset): dynamicimages_asset + { + // Draw a centered step counter number on the button + $font = $this->getFontPath('AlfaSlabOne-Regular.ttf'); + $imgW = $buttonAsset->getWidth(); + $imgH = $buttonAsset->getHeight(); + // Virtual badge used only to size text well (no circle is drawn) + $badgeDiameter = 0.40 * min($imgW, $imgH); + $badgeRadius = $badgeDiameter / 2.0; + + // Badge center equals image center + $cx = $imgW / 2.0; + $cy = $imgH / 2.0; + // With center/center alignment, offsets are deltas from image center + $xOffset = (int)round($cx - ($imgW / 2.0)); + $yOffset = (int)round($cy - ($imgH / 2.0)); + + // Dynamic font sizing to fit up to 2 digits inside the virtual badge + $targetFrac = 0.72; // 72% of diameter + $maxBox = $badgeDiameter * $targetFrac; + $fontSize = (int)max(1, round($badgeDiameter * 0.6)); + try { + $im = $buttonAsset->getMemoryImage(); + if ($im instanceof \Imagick) { + $draw = new \ImagickDraw(); + $draw->setFont($font); + for ($i = 0; $i < 6; $i++) { + $draw->setFontSize($fontSize); + $metrics = $im->queryFontMetrics($draw, (string)$this->getNextButtonStepCount(), false); + $this->button_counter--; // undo increment from metrics call + $textW = (int)ceil($metrics['textWidth'] ?? 0); + $textH = (int)ceil(($metrics['ascender'] ?? 0) - ($metrics['descender'] ?? 0)); + if ($textW > $maxBox || $textH > $maxBox) { + $fontSize = (int)max(1, floor($fontSize * 0.9)); + } else { + $next = (int)ceil($fontSize * 1.05); + if ($next === $fontSize) { + break; + } + $fontSize = $next; + } + } + // Safety: ensure we don't exceed the box + $draw->setFontSize($fontSize); + $metrics = $im->queryFontMetrics($draw, (string)$this->getNextButtonStepCount(), false); + $this->button_counter--; // undo increment from metrics call + $textW = (int)ceil($metrics['textWidth'] ?? 0); + $textH = (int)ceil(($metrics['ascender'] ?? 0) - ($metrics['descender'] ?? 0)); + if ($textW > $maxBox || $textH > $maxBox) { + $fontSize = (int)max(1, floor($fontSize * 0.95)); + } + } + } catch (\Throwable $e) { + // Fallback to initial estimate + } + + $angle = 0; + $color = [255, 255, 255]; + $text = (string)$this->getNextButtonStepCount(); + // If the step has been completed, do not draw the number + if ($this->button_counter <= $this->current_step) { + $text = ''; + } + + $buttonAsset->addTextOverlay($text, [ + 'font_size' => $fontSize, + 'font_color' => $color, + 'font_path' => $font, + 'x_offset' => $xOffset, + 'y_offset' => $yOffset, + 'angle' => $angle, + 'align' => 'center', + 'valign' => 'center', + ]); + + return $buttonAsset; + } + + public function drawStepCounterOnButtonTopRight(dynamicimages_asset $buttonAsset): dynamicimages_asset { $font = $this->getFontPath('AlfaSlabOne-Regular.ttf'); // The blue badge circle occupies 25% of the button width/height (diameter) diff --git a/services/nginx/app/routes/exampleRoute.php b/services/nginx/app/routes/exampleRoute.php index 63294668..f15b4e4a 100644 --- a/services/nginx/app/routes/exampleRoute.php +++ b/services/nginx/app/routes/exampleRoute.php @@ -4,6 +4,7 @@ namespace routes; use classes\entra; use classes\redis; +use dynamicimages\images\machine_1; use goals\classes\goals; use goals\classes\goals_criteria; use objects\departments_o; @@ -53,22 +54,18 @@ class exampleRoute $this->get('/debug', function () { global $response; - $criteria = (new goals_criteria()); - $criteria->type = \goals\helpers\goals_criteria_type::PRODUCT; - $criteria->target = 100; - $criteria->products->add((new products_o())->select(1)); - $criteria->users->add((new users_o())->getUserByCustomerNumber(12345679)); - $criteria->departments->add([ - (new departments_o())->select(1), - (new departments_o())->select(2), - (new departments_o())->select(3), - ]); - $criteria->setTimeframe(new \DateTime('2026-01-01'), new \DateTime('2026-01-31')); - $goal = new goals($criteria); - echo 'Result: ' . $goal->getResult() . PHP_EOL; - echo 'Percentage: ' . $goal->getPercentage() . '%' . PHP_EOL; - echo 'Remaining: ' . $goal->getRemaining() . PHP_EOL; - $response->success(['message' => 'Debugging route!']); + //$response->success(['message' => 'Debugging route!']); + $machine_1 = new machine_1(); + //$machine_1->debugAssets(); + $machine_1->current_step = 0; + $machine_1->only_generate_current_step = false; + $machine_1->highlighted_buttons = [ + 0, 2, 4, 7 + ]; + $machine_1->setup(); + $machine_1->servePicture(); + exit; + $response->success(['message' => 'Debugging route!', 'base64_image' => $machine_1->exportAsBase64()]); }); } } \ No newline at end of file