Files
api/services/nginx/app/modules/dynamicimages/images/machine_1.php
T
Jeppe Bundgaard 2e7376f00a Add centered asset drawing support and refine image transformations
- Introduce `drawAssetCentered` method in `dynamicimages_image_t` for drawing assets visually centered on specified coordinates.
- Reset virtual canvas/page after image rotation in both `dynamicimages_asset_t` and `dynamicimages_image_t` to ensure consistent positioning.
- Update `machine_1` logic to use `drawAssetCentered` for improved thumb drawing and dynamic pivot alignment.
- Adjust thumb rotation calculations and positioning logic for better visual rendering.
2026-01-27 14:56:58 +01:00

73 lines
3.1 KiB
PHP

<?php
namespace dynamicimages\images;
use dynamicimages\classes\dynamicimages_asset;
use dynamicimages\classes\dynamicimages_image;
class machine_1 extends dynamicimages_image
{
const IMAGE_POWER_BUTTON = 'machine_1_button_start_stop.png';
const IMAGE_PANEL_BACKGROUND = 'machine_1_panel_background.png';
const IMAGE_WASH_PROGRAMS_THUMB = 'machine_1_wash_programs_thumb_standalone_transparent.png';
const IMAGE_WASH_PROGRAMS = 'machine_1_wash_programs_transparent.png';
public int $thumb_position = 0; // 1-12 (default: 0 = up = 270 degrees)
/**
* @throws \Exception
*/
public function __construct()
{
$this->setAssetPath(self::asset_path . str_replace(__NAMESPACE__ . '\\', '', __CLASS__) . '/');
parent::__construct([
new dynamicimages_asset(self::getAssetPath(self::IMAGE_POWER_BUTTON)),
new dynamicimages_asset(self::getAssetPath(self::IMAGE_PANEL_BACKGROUND)),
new dynamicimages_asset(self::getAssetPath(self::IMAGE_WASH_PROGRAMS_THUMB)),
new dynamicimages_asset(self::getAssetPath(self::IMAGE_WASH_PROGRAMS)),
]);
}
/**
* @throws \Exception
*/
public function setup(): void
{
$this->initImageCanvas(6000, 4500);
// By default, the background should be shown with the programs on top and then on top of that the thumb 464 -> 311 = 1500 -> 1000
$this->drawAsset($this->getAsset(self::IMAGE_PANEL_BACKGROUND), 0, 0);
$this->drawAsset($this->getAsset(self::IMAGE_WASH_PROGRAMS), 0, 0);
$thumbHeight = 1550;
$thumbX = 620;
$thumbY = 1290;
// Base resized thumb to compute the visual pivot (center coordinates)
$baseThumb = $this->getAsset(self::IMAGE_WASH_PROGRAMS_THUMB)->resize($this->calculateThumbWidth($thumbHeight), $thumbHeight);
$centerX = $thumbX + (int)floor($baseThumb->getWidth() / 2);
$centerY = $thumbY + (int)floor($baseThumb->getHeight() / 2);
$tmp = new dynamicimages_asset($this->getAssetPath(self::IMAGE_WASH_PROGRAMS_THUMB));
$tmp->resize($this->calculateThumbWidth($thumbHeight), $thumbHeight)
->rotate($this->getRotationThumbPosition());
$this->drawAssetCentered($tmp, $centerX, $centerY);
// Free memory used by temporary asset image, if any
if (method_exists($tmp, 'clearMemoryImage')) {
$tmp->clearMemoryImage();
}
$this->drawAsset($this->getAsset(self::IMAGE_WASH_PROGRAMS), 0, 0);
//$this->drawAsset($this->getAsset(self::IMAGE_POWER_BUTTON), 0, 0);
}
public function getRotationThumbPosition(): float
{
// Each position represents a 30 degree increment (12 positions in total for 360 degrees)
$degrees = -90;
return ($this->thumb_position) * 30 + $degrees;
}
public function calculateThumbWidth(int $height): int
{
$originalWidth = $this->getAsset(self::IMAGE_WASH_PROGRAMS_THUMB)->getWidth();
$originalHeight = $this->getAsset(self::IMAGE_WASH_PROGRAMS_THUMB)->getHeight();
return (int)round(($originalWidth / $originalHeight) * $height);
}
}