aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Repair/RepairLogoDimension.php
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2024-07-10 15:29:45 +0200
committerJoas Schilling <coding@schilljs.com>2024-07-17 09:24:55 +0200
commit693a81bfa367089de4b61ee1ea104c85e6bc6d1c (patch)
treefc98b9adef2985e640f1cf9f95d91f63dd7257f8 /lib/private/Repair/RepairLogoDimension.php
parent2f9fcc22aec918a9d07603b5e481d43bfb980ba0 (diff)
downloadnextcloud-server-693a81bfa367089de4b61ee1ea104c85e6bc6d1c.tar.gz
nextcloud-server-693a81bfa367089de4b61ee1ea104c85e6bc6d1c.zip
fix(mail): Fix big logos in mail templates for Outlook
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/Repair/RepairLogoDimension.php')
-rw-r--r--lib/private/Repair/RepairLogoDimension.php71
1 files changed, 71 insertions, 0 deletions
diff --git a/lib/private/Repair/RepairLogoDimension.php b/lib/private/Repair/RepairLogoDimension.php
new file mode 100644
index 00000000000..122da205986
--- /dev/null
+++ b/lib/private/Repair/RepairLogoDimension.php
@@ -0,0 +1,71 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OC\Repair;
+
+use OCA\Theming\ImageManager;
+use OCP\IConfig;
+use OCP\Migration\IOutput;
+use OCP\Migration\IRepairStep;
+use OCP\Server;
+
+class RepairLogoDimension implements IRepairStep {
+ public function __construct(
+ protected IConfig $config,
+ ) {
+ }
+
+ public function getName(): string {
+ return 'Cache logo dimension to fix size in emails on Outlook';
+ }
+
+ public function run(IOutput $output): void {
+ $logoDimensions = $this->config->getAppValue('theming', 'logoDimensions');
+ if (preg_match('/^\d+x\d+$/', $logoDimensions)) {
+ $output->info('Logo dimensions are already known');
+ return;
+ }
+
+ try {
+ /** @var ImageManager $imageManager */
+ $imageManager = Server::get(ImageManager::class);
+ } catch (\Throwable) {
+ $output->info('Theming is disabled');
+ return;
+ }
+
+ if (!$imageManager->hasImage('logo')) {
+ $output->info('Theming is not used to provide a logo');
+ return;
+ }
+
+ $simpleFile = $imageManager->getImage('logo', false);
+
+ $image = @imagecreatefromstring($simpleFile->getContent());
+
+ $dimensions = '';
+ if ($image !== false) {
+ $dimensions = imagesx($image) . 'x' . imagesy($image);
+ } elseif (str_starts_with($simpleFile->getMimeType(), 'image/svg')) {
+ $matched = preg_match('/viewbox=["\']\d* \d* (\d*\.?\d*) (\d*\.?\d*)["\']/i', $simpleFile->getContent(), $matches);
+ if ($matched) {
+ $dimensions = $matches[1] . 'x' . $matches[2];
+ }
+ }
+
+ if (!$dimensions) {
+ $output->warning('Failed to read dimensions from logo');
+ $this->config->deleteAppValue('theming', 'logoDimensions');
+ return;
+ }
+
+ $dimensions = imagesx($image) . 'x' . imagesy($image);
+ $this->config->setAppValue('theming', 'logoDimensions', $dimensions);
+ $output->info('Updated logo dimensions: ' . $dimensions);
+ }
+}