Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
abordage committed May 28, 2022
1 parent b9d3620 commit 04e7606
Showing 1 changed file with 31 additions and 39 deletions.
70 changes: 31 additions & 39 deletions src/OpenGraphImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,18 @@ public function __construct(array $config = [])
$this->appNameDecorationStyle = $config['app_name_decoration_style'];
$this->appNameDecorationColor = $config['app_name_decoration_color'];

$positions = [
'left-top' => 'top-left',
'center-top' => 'top-center',
'right-top' => 'top-right',

'left-bottom' => 'bottom-left',
'center-bottom' => 'bottom-center',
'right-bottom' => 'bottom-right',
];

$this->appNamePosition = str_replace(array_keys($positions), array_values($positions), $this->appNamePosition);

if (!is_null($this->fontPath) && file_exists($this->fontPath)) {
$this->font = $this->fontPath;
}
Expand Down Expand Up @@ -539,21 +551,7 @@ protected function setAppNameParameters(): void
{
$this->setAppNameBox();
$this->setAppNameCoordinates();

switch ($this->appNameDecorationStyle) {
case 'line':
$this->setLineCoordinates();

break;
case 'label':
$this->setLabelCoordinates();

break;
case 'rectangle':
$this->setRectangleCoordinates();

break;
}
$this->setAppDecorationCoordinates();
}

/**
Expand Down Expand Up @@ -585,42 +583,54 @@ protected function setAppNameCoordinates(): void

switch ($this->appNamePosition) {
case 'top-left':
case 'left-top':
$this->appNameStartX = $this->appNameDefaultPaddingX;

break;
case 'top-center':
case 'center-top':
$this->appNameStartX = intval(($this->imageWidth / 2) - ($this->appNameBoxWidth / 2));

break;
case 'top-right':
case 'right-top':
default:
$this->appNameStartX = $this->imageWidth - $this->appNameDefaultPaddingX - $this->appNameBoxWidth;

break;
case 'bottom-left':
case 'left-bottom':
$this->appNameStartY = $this->imageHeight - $this->appNameDefaultPaddingY - $this->appNameBoxHeight;
$this->appNameStartX = $this->appNameDefaultPaddingX;

break;
case 'bottom-center':
case 'center-bottom':
$this->appNameStartY = $this->imageHeight - $this->appNameDefaultPaddingY - $this->appNameBoxHeight;
$this->appNameStartX = intval(($this->imageWidth / 2) - ($this->appNameBoxWidth / 2));

break;
case 'bottom-right':
case 'right-bottom':
$this->appNameStartY = $this->imageHeight - $this->appNameDefaultPaddingY - $this->appNameBoxHeight;
$this->appNameStartX = $this->imageWidth - $this->appNameDefaultPaddingX - $this->appNameBoxWidth;

break;
}
}

protected function setAppDecorationCoordinates(): void
{
switch ($this->appNameDecorationStyle) {
case 'line':
$this->setLineCoordinates();

break;
case 'label':
$this->setLabelCoordinates();

break;
case 'rectangle':
$this->setRectangleCoordinates();

break;
}
}

protected function setLineCoordinates(): void
{
$defaultPaddingLine = 7;
Expand All @@ -630,18 +640,12 @@ protected function setLineCoordinates(): void
case 'top-left':
case 'top-center':
case 'top-right':
case 'left-top':
case 'center-top':
case 'right-top':
$this->rectangleY1 = $this->appNameStartY + $this->appNameBoxHeight + $defaultPaddingLine;

break;
case 'bottom-left':
case 'bottom-center':
case 'bottom-right':
case 'center-bottom':
case 'right-bottom':
case 'left-bottom':
default:
$this->rectangleY1 = $this->appNameStartY - $defaultPaddingLine - $rectangleHeight;
}
Expand All @@ -658,7 +662,6 @@ protected function setLabelCoordinates(): void

switch ($this->appNamePosition) {
case 'top-left':
case 'left-top':
$this->rectangleX1 = 0;
$this->rectangleY1 = 0;

Expand All @@ -667,7 +670,6 @@ protected function setLabelCoordinates(): void

break;
case 'bottom-left':
case 'left-bottom':
$this->rectangleX1 = 0;
$this->rectangleY1 = $this->imageHeight - $rectangleHeight;

Expand All @@ -676,9 +678,7 @@ protected function setLabelCoordinates(): void

break;
case 'top-center':
case 'center-top':
case 'bottom-center':
case 'center-bottom':
default:
$this->rectangleX1 = 0;
$this->rectangleY1 = 0;
Expand All @@ -688,7 +688,6 @@ protected function setLabelCoordinates(): void

break;
case 'top-right':
case 'right-top':
$this->rectangleX1 = $this->imageWidth - $rectangleWidth;
$this->rectangleY1 = 0;

Expand All @@ -697,7 +696,6 @@ protected function setLabelCoordinates(): void

break;
case 'bottom-right':
case 'right-bottom':
$this->rectangleX1 = $this->imageWidth - $rectangleWidth;
$this->rectangleY1 = $this->imageHeight - $rectangleHeight;

Expand All @@ -716,7 +714,6 @@ protected function setRectangleCoordinates(): void

switch ($this->appNamePosition) {
case 'top-left':
case 'left-top':
$this->rectangleX1 = 0;
$this->rectangleY1 = 0;

Expand All @@ -725,7 +722,6 @@ protected function setRectangleCoordinates(): void

break;
case 'bottom-left':
case 'left-bottom':
$this->rectangleX1 = 0;
$this->rectangleY1 = $this->imageHeight - $rectangleHeight;

Expand All @@ -734,7 +730,6 @@ protected function setRectangleCoordinates(): void

break;
case 'top-center':
case 'center-top':
$this->rectangleX1 = $this->appNameStartX - $defaultPaddingCenterLabel;
$this->rectangleY1 = 0;

Expand All @@ -743,7 +738,6 @@ protected function setRectangleCoordinates(): void

break;
case 'bottom-center':
case 'center-bottom':
default:
$this->rectangleX1 = $this->appNameStartX - $defaultPaddingCenterLabel;
$this->rectangleY1 = $this->imageHeight - $rectangleHeight;
Expand All @@ -753,7 +747,6 @@ protected function setRectangleCoordinates(): void

break;
case 'top-right':
case 'right-top':
$this->rectangleX1 = $this->imageWidth - $rectangleWidth;
$this->rectangleY1 = 0;

Expand All @@ -762,7 +755,6 @@ protected function setRectangleCoordinates(): void

break;
case 'bottom-right':
case 'right-bottom':
$this->rectangleX1 = $this->imageWidth - $rectangleWidth;
$this->rectangleY1 = $this->imageHeight - $rectangleHeight;

Expand Down

0 comments on commit 04e7606

Please sign in to comment.