mirror of
https://github.com/antonkomarev/github-profile-views-counter.git
synced 2026-07-29 08:42:38 -04:00
Fix dynamic length
This commit is contained in:
@@ -34,9 +34,24 @@ final class CounterImageRendererService
|
||||
$this->counterRepository->incrementCount();
|
||||
$count = $this->counterRepository->getCount();
|
||||
|
||||
$minImageWidth = 98;
|
||||
$minCounterBackgroundWidth = 17;
|
||||
$minCounterTextLength = 70;
|
||||
$minCounterTextMarginLeft = 885;
|
||||
|
||||
$countLength = $this->countIntegerLength($count);
|
||||
$counterImage = file_get_contents($this->sourceImagePath);
|
||||
$counterImage = str_replace('%COUNT%', $count, $counterImage);
|
||||
$counterImage = str_replace('%IMAGE_WIDTH%', $minImageWidth + (8 * $countLength), $counterImage);
|
||||
$counterImage = str_replace('%COUNTER_BACKGROUND_WIDTH%', $minCounterBackgroundWidth + (8 * $countLength), $counterImage);
|
||||
$counterImage = str_replace('%COUNTER_TEXT_LENGTH%', $minCounterTextLength + (80 * $countLength), $counterImage);
|
||||
$counterImage = str_replace('%COUNTER_TEXT_MARGIN_LEFT%', $minCounterTextMarginLeft + (40 * $countLength), $counterImage);
|
||||
|
||||
return $counterImage;
|
||||
}
|
||||
|
||||
private function countIntegerLength(int $integer): int
|
||||
{
|
||||
return strlen((string) $integer);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user