Files
api/services/nginx/app/modules/dynamicimages/images/machine_1.php
T
Jeppe Bundgaard 43eeb14099 Update machine_1 default thumb position and adjust thumb X-coordinate positioning
- Set `$thumb_position` default value to `10` for improved alignment.
- Tweak thumb X-coordinate from `620` to `650` for better rendering consistency.
2026-01-27 15:04:17 +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 = 10; // 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
$this->drawAsset($this->getAsset(self::IMAGE_PANEL_BACKGROUND), 0, 0);
$this->drawAsset($this->getAsset(self::IMAGE_WASH_PROGRAMS), 0, 0);
$thumbHeight = 1550;
$thumbX = 650;
$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);
}
}