Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/Writer/EpsWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,43 @@
}
}

if ($logo instanceof LogoInterface) {
$this->addLogo($logo, $lines, $matrix->getOuterSize());
}

return new EpsResult($matrix, $lines);
}

private function addLogo(LogoInterface $logo, array &$lines, int $outerSize): void

Check failure on line 49 in src/Writer/EpsWriter.php

View workflow job for this annotation

GitHub Actions / build (8.2)

Method Endroid\QrCode\Writer\EpsWriter::addLogo() has parameter $lines with no value type specified in iterable type array.

Check failure on line 49 in src/Writer/EpsWriter.php

View workflow job for this annotation

GitHub Actions / build (8.3)

Method Endroid\QrCode\Writer\EpsWriter::addLogo() has parameter $lines with no value type specified in iterable type array.

Check failure on line 49 in src/Writer/EpsWriter.php

View workflow job for this annotation

GitHub Actions / build (8.4)

Method Endroid\QrCode\Writer\EpsWriter::addLogo() has parameter $lines with no value type specified in iterable type array.

Check failure on line 49 in src/Writer/EpsWriter.php

View workflow job for this annotation

GitHub Actions / build (8.2)

Method Endroid\QrCode\Writer\EpsWriter::addLogo() has parameter $lines with no value type specified in iterable type array.

Check failure on line 49 in src/Writer/EpsWriter.php

View workflow job for this annotation

GitHub Actions / build (8.3)

Method Endroid\QrCode\Writer\EpsWriter::addLogo() has parameter $lines with no value type specified in iterable type array.

Check failure on line 49 in src/Writer/EpsWriter.php

View workflow job for this annotation

GitHub Actions / build (8.4)

Method Endroid\QrCode\Writer\EpsWriter::addLogo() has parameter $lines with no value type specified in iterable type array.
{
$logoPath = $logo->getPath();
$logoHeight = $logo->getResizeToHeight();
$logoWidth = $logo->getResizeToWidth();

if (null === $logoHeight || null === $logoWidth) {
$imageSize = \getimagesize($logoPath);
if (!$imageSize) {
throw new \Exception(sprintf('Unable to read image size for logo "%s"', $logoPath));
}
[$logoSourceWidth, $logoSourceHeight] = $imageSize;

if (null === $logoWidth) {
$logoWidth = (int) $logoSourceWidth;
}

if (null === $logoHeight) {
$aspectRatio = $logoWidth / $logoSourceWidth;
$logoHeight = (int) ($logoSourceHeight * $aspectRatio);
}
}

$logoX = $outerSize / 2 - $logoWidth / 2;
$logoY = $outerSize / 2 - $logoHeight / 2;

$lines[] = 'gsave';
$lines[] = number_format($logoX, self::DECIMAL_PRECISION, '.', '').' '.number_format($logoY, self::DECIMAL_PRECISION, '.', '').' translate';
$lines[] = number_format($logoWidth, self::DECIMAL_PRECISION, '.', '').' '.number_format($logoHeight, self::DECIMAL_PRECISION, '.', '').' scale';
$lines[] = '('.$logoPath.') run';
$lines[] = 'grestore';
}
}
27 changes: 27 additions & 0 deletions tests/Writer/EpsWriterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Endroid\QrCode\Tests\Writer;

use Endroid\QrCode\QrCode;
use Endroid\QrCode\Writer\EpsWriter;
use Endroid\QrCode\Logo\Logo;
use PHPUnit\Framework\TestCase;

final class EpsWriterTest extends TestCase
{
public function testWriteWithLogo(): void
{
$qrCode = new QrCode('QR Code with logo');
$logo = new Logo(__DIR__.'/../assets/symfony.svg', 50, 50);

$writer = new EpsWriter();
$result = $writer->write($qrCode, $logo);

$this->assertStringContainsString('gsave', $result->getString());
$this->assertStringContainsString('translate', $result->getString());
$this->assertStringContainsString('scale', $result->getString());
$this->assertStringContainsString('run', $result->getString());
}
}
Loading