Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-macquer-omnilog committed Nov 4, 2024
1 parent 775edd9 commit e671c2c
Showing 1 changed file with 140 additions and 20 deletions.
160 changes: 140 additions & 20 deletions src/Command/MergeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,22 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$romans = [
['MMMMMXXXVIII', 'MMMMCCXLV'],
['MMMMMDCCCXVI', 'MMMMMDCCXXV'],
['MMMMMDCXXVI', 'MMMMMMMCXIX'],
['MMMCCXX', 'MMMMMCXXIII'],
[' MMMMMDCXXVI', 'MMMMMMMCXIX'],
[' MMMCCXX', 'MMMMMCXXIII'],
['MMMMMMMCDLVII', 'MMCCLIV'],
['MMMMMMMDXLII', 'MMMMMMMCCLVIII'],
[' MMMMMMMDXLII', 'MMMMMMMCCLVIII'],
['MMMMMMMMCXLIX', 'MMMMMMCDXLV'],
['CXII', 'MMMMMMDCCLIV', 'MMMMMML'],
['MMMMMMCXVIII', 'MDCCXIX'],
[' CXII', 'MMMMMMDCCLIV', 'MMMMMML'],
[' MMMMMMCXVIII', 'MDCCXIX'],
['MMMMMXXXII', 'MMMMMCCXIII'],
['MMMMMMMMXXX', 'LIX'],
[' MMMMMMMMXXX', 'LIX'],
];

$numbers = [];

foreach ($romans as $romanArray) {
$numbers[] = array_map(
fn (string $roman): int => $this->romanToNumberConverterService->convertRomanToNumber($roman),
fn (string $roman): int => $this->romanToNumberConverterService->convertRomanToNumber(trim($roman)),
$romanArray
);
}
Expand All @@ -81,18 +81,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
[8030, 59],
];

foreach ($numbers as $line) {
foreach ($line as &$number) {
$first2Digits = (int) substr((string) $number, 0, 2);
$last2Digits = (int) substr((string) $number, 2, 2);
$first2Digits += 10;
$last2Digits += 99;
$number = $first2Digits . $last2Digits;
}
}

$output->writeln('Merging png files...');

$timestamp = (new DateTime())->getTimestamp();

$this->outputDirectory .= $timestamp . '/';
Expand Down Expand Up @@ -596,7 +584,7 @@ private function generateOneLineSideToSideMerged(array $numbers): void

imagepng($outputImage, $this->outputDirectory . '/2-output-side-to-side-merged.png');
}

/**
* @param array<int, array<int>> $numbers
*/
Expand Down Expand Up @@ -733,4 +721,136 @@ private function generateTruncatedOutput(): void
imagepng($outputImage, str_replace('.png', '-truncated.png', $file));
}
}

/**
* @param array<int, array<int>> $numbers
*/
private function generateMultipleLinesMergedWithShiftQuarterSpace(array $numbers): void
{
$outputWidth = $this->widthOfOneImage * 6 + $this->mergePadding;
$outputHeight = count($numbers) * $this->heightOfOneImage + $this->mergePadding;
$outputImage = imagecreatetruecolor($outputWidth, $outputHeight);
$white = imagecolorallocate($outputImage, 255, 255, 255);

if (false === $white) {
throw new RuntimeException('Failed to allocate color');
}

imagefill($outputImage, 0, 0, $white);

$i = 1;
$x = 0;
$y = 0;
$linesWithShift = [3, 4, 6, 8, 9, 11];
$image = null;

foreach ($numbers as $line) {
$j = 1;

foreach ($line as $number) {
$image = imagecreatefrompng(
$this->cistercianNumberGeneratorService->generateCistercianNumber($number)
);

if (false === $image) {
throw new RuntimeException('Failed to create image');
}

$x = (int) floor($this->mergePadding / 2);

if (in_array($i, $linesWithShift, true) && 1 === $j) {
//$x += (int) floor($this->widthOfOneImage / 2);
$x += (int) floor($this->widthOfOneImage / 4);
}

imagecopy(
$outputImage,
$image,
$x,
$y + (int) floor($this->mergePadding / 2),
0,
0,
imagesx($image),
imagesy($image)
);
$j++;
}

if (null === $image) {
continue;
}

$x = 0;
$y += imagesy($image) - $this->lineThickness;
$i++;
}

imagepng($outputImage, $this->outputDirectory . '/9-output-multiple-lines-shifted-merged-quarter-space.png');
}

/**
* @param array<int, array<int>> $numbers
*/
private function generateMultipleLinesUnmergedWithShiftQuarterSpace(array $numbers): void
{
$outputWidth = $this->widthOfOneImage * 6 + $this->mergePadding;
$outputHeight = count($numbers) * $this->heightOfOneImage + $this->mergePadding;
$outputImage = imagecreatetruecolor($outputWidth, $outputHeight);
$white = imagecolorallocate($outputImage, 255, 255, 255);

if (false === $white) {
throw new RuntimeException('Failed to allocate color');
}

imagefill($outputImage, 0, 0, $white);

$i = 1;
$x = 0;
$y = 0;
$linesWithShift = [3, 4, 6, 8, 9, 11];
$image = null;

foreach ($numbers as $line) {
$j = 1;

foreach ($line as $number) {
$image = imagecreatefrompng(
$this->cistercianNumberGeneratorService->generateCistercianNumber($number)
);

if (false === $image) {
throw new RuntimeException('Failed to create image');
}

$x += (int) floor($this->mergePadding / 2);

if (in_array($i, $linesWithShift, true) && 1 === $j) {
$x += (int) $this->widthOfOneImage / 2 - (int) ($this->lineThickness / 4);
}

imagecopy(
$outputImage,
$image,
(int) $x,
$y + (int) floor($this->mergePadding / 2),
0,
0,
imagesx($image),
imagesy($image)
);
$x += imagesx($image) - $this->lineThickness - (int) floor($this->mergePadding / 2);
$j++;
}

if (null === $image) {
continue;
}

$x = 0;
$y += imagesy($image) - $this->lineThickness;
$i++;
}

imagepng($outputImage, $this->outputDirectory . '/10-output-multiple-lines-shifted-unmerged-quarter-space.png');
}
}

0 comments on commit e671c2c

Please sign in to comment.