From 55cb43ddc320f873e922c72d82abf4fdaec54a0c Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 4 Mar 2024 14:25:59 +0100 Subject: [PATCH] wip #6765 @0.25 --- app/Elearning/QuizCompiler.php | 2 +- app/Models/QuizTheme.php | 44 ++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/app/Elearning/QuizCompiler.php b/app/Elearning/QuizCompiler.php index bc0e1f15c..5e390a1b0 100644 --- a/app/Elearning/QuizCompiler.php +++ b/app/Elearning/QuizCompiler.php @@ -85,7 +85,7 @@ class QuizCompiler extends Base $vdir = new VirtualDirectory($this->dest); $vdir->copyDirectory($this->compilePath . '/dist/css', 'css'); $vdir->copyDirectory($this->compilePath . '/dist/js', 'js'); - $vdir->copyDirectory($this->compilePath . '/dist/assets', 'assets'); + $vdir->copyDirectory($this->compilePath . '/dist/assets', 'assets',false); $l10n = $this->data->l10n; $blade = new Blade($this->_resourcesPath() . '/views', $this->_resourcesPath() . '/cache/' . md5(rand(100000, 10000000)) . '/'); diff --git a/app/Models/QuizTheme.php b/app/Models/QuizTheme.php index 3bdc8cd2f..907ead57f 100644 --- a/app/Models/QuizTheme.php +++ b/app/Models/QuizTheme.php @@ -223,8 +223,8 @@ class QuizTheme extends ToolboxModel $data = ['mainColor' => (string)$quiz->mainColor, 'okColor' => (string)$quiz->okColor, 'nokColor' => (string)$quiz->nokColor, - 'logo' => hash_file('sha256', $logo), - 'banner' => hash_file('sha256', $banner), + 'logo' => $logo ? hash_file('sha256', $logo) : '', + 'banner' => $banner ? hash_file('sha256', $banner) : '', 'overlay' => (string)$quiz->overlay, ]; $hash = hash('sha256', print_r($data, true)); @@ -246,27 +246,32 @@ class QuizTheme extends ToolboxModel $theme->owner = $quiz->owner; - $logo = new \SplFileInfo($logo); - $tmp = Files::tempnam() . '.' . $logo->getExtension(); - copy($logo, $tmp); - $theme->addMediaToField('logo', $tmp); - - $theme->backgroundCustom = '1'; + if ($logo) { + $logo = new \SplFileInfo($logo); + $tmp = Files::tempnam() . '.' . $logo->getExtension(); + copy($logo, $tmp); + $theme->addMediaToField('logo', $tmp); + $theme->backgroundCustom = '1'; + } $theme->font = 'SourceSans'; - $avg = Imagemagick::getAverageColor($banner); - $distance = $avg->distance(new \Cubist\Util\Graphics\Color('#fff')); - $darken = $distance <= 20000000; + if ($banner) { + $avg = Imagemagick::getAverageColor($banner); + $distance = $avg->distance(new \Cubist\Util\Graphics\Color('#fff')); + $darken = $distance <= 20000000; - if ($darken) { - $tmp = Files::tempnam() . '.jpg'; - Imagemagick::brightnessContrast($banner, $tmp, -20); - $banner = $tmp; - } + if ($darken) { + $tmp = Files::tempnam() . '.jpg'; + Imagemagick::brightnessContrast($banner, $tmp, -20); + $banner = $tmp; + } - $theme->addMediaToField('backgroundImage', self::resizeAndBlur($banner, 1200, 680)); - $theme->addMediaToField('backgroundImageMobile', self::resizeAndBlur($banner, 390, 844)); + $theme->addMediaToField('backgroundImage', self::resizeAndBlur($banner, 1200, 680)); + $theme->addMediaToField('backgroundImageMobile', self::resizeAndBlur($banner, 390, 844)); + } else { + $theme->backgroundColor = '#aaa'; + } $theme->save(); return $theme->id; @@ -283,10 +288,9 @@ class QuizTheme extends ToolboxModel $resizer->resize($width, $height, true, true); $resizer->output('jpg', $tmp); - Imagemagick::blur($tmp, $blur); - unlink($tmp); + Files::unlink($tmp); return $blur; } -- 2.39.5