-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42977 from nextcloud/theming/create-color-from-ba…
…ckground theming: Separate `primary` and `background` colors - fix the header menu colors
- Loading branch information
Showing
76 changed files
with
1,473 additions
and
799 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
* | ||
* @author Christoph Wurst <[email protected]> | ||
* @author Daniel Kesselberg <[email protected]> | ||
* @author Ferdinand Thiessen <[email protected]> | ||
* @author Gary Kim <[email protected]> | ||
* @author Jacob Neplokh <[email protected]> | ||
* @author John Molakvoæ <[email protected]> | ||
|
@@ -56,6 +57,7 @@ public function __construct( | |
private ICacheFactory $cacheFactory, | ||
private LoggerInterface $logger, | ||
private ITempManager $tempManager, | ||
private BackgroundService $backgroundService, | ||
) { | ||
} | ||
|
||
|
@@ -77,7 +79,11 @@ public function getImageUrl(string $key): string { | |
case 'favicon': | ||
return $this->urlGenerator->imagePath('core', 'logo/logo.png') . '?v=' . $cacheBusterCounter; | ||
case 'background': | ||
return $this->urlGenerator->linkTo(Application::APP_ID, 'img/background/' . BackgroundService::DEFAULT_BACKGROUND_IMAGE); | ||
// Removing the background defines its mime as 'backgroundColor' | ||
$mimeSetting = $this->config->getAppValue('theming', 'backgroundMime', ''); | ||
if ($mimeSetting !== 'backgroundColor') { | ||
return $this->urlGenerator->linkTo(Application::APP_ID, 'img/background/' . BackgroundService::DEFAULT_BACKGROUND_IMAGE); | ||
} | ||
} | ||
return ''; | ||
} | ||
|
@@ -227,47 +233,56 @@ public function updateImage(string $key, string $tmpFile): string { | |
throw new \Exception('Unsupported image type: ' . $detectedMimeType); | ||
} | ||
|
||
if ($key === 'background' && $this->shouldOptimizeBackgroundImage($detectedMimeType, filesize($tmpFile))) { | ||
try { | ||
// Optimize the image since some people may upload images that will be | ||
// either to big or are not progressive rendering. | ||
$newImage = @imagecreatefromstring(file_get_contents($tmpFile)); | ||
if ($newImage === false) { | ||
throw new \Exception('Could not read background image, possibly corrupted.'); | ||
} | ||
if ($key === 'background') { | ||
if ($this->shouldOptimizeBackgroundImage($detectedMimeType, filesize($tmpFile))) { | ||
try { | ||
// Optimize the image since some people may upload images that will be | ||
// either to big or are not progressive rendering. | ||
$newImage = @imagecreatefromstring(file_get_contents($tmpFile)); | ||
if ($newImage === false) { | ||
throw new \Exception('Could not read background image, possibly corrupted.'); | ||
} | ||
|
||
// Preserve transparency | ||
imagesavealpha($newImage, true); | ||
imagealphablending($newImage, true); | ||
// Preserve transparency | ||
imagesavealpha($newImage, true); | ||
imagealphablending($newImage, true); | ||
|
||
$newWidth = (imagesx($newImage) < 4096 ? imagesx($newImage) : 4096); | ||
$newHeight = (int)(imagesy($newImage) / (imagesx($newImage) / $newWidth)); | ||
$outputImage = imagescale($newImage, $newWidth, $newHeight); | ||
if ($outputImage === false) { | ||
throw new \Exception('Could not scale uploaded background image.'); | ||
} | ||
$imageWidth = imagesx($newImage); | ||
$imageHeight = imagesy($newImage); | ||
|
||
$newTmpFile = $this->tempManager->getTemporaryFile(); | ||
imageinterlace($outputImage, true); | ||
// Keep jpeg images encoded as jpeg | ||
if (str_contains($detectedMimeType, 'image/jpeg')) { | ||
if (!imagejpeg($outputImage, $newTmpFile, 90)) { | ||
throw new \Exception('Could not recompress background image as JPEG'); | ||
/** @var int */ | ||
$newWidth = min(4096, $imageWidth); | ||
$newHeight = intval($imageHeight / ($imageWidth / $newWidth)); | ||
$outputImage = imagescale($newImage, $newWidth, $newHeight); | ||
if ($outputImage === false) { | ||
throw new \Exception('Could not scale uploaded background image.'); | ||
} | ||
} else { | ||
if (!imagepng($outputImage, $newTmpFile, 8)) { | ||
throw new \Exception('Could not recompress background image as PNG'); | ||
|
||
$newTmpFile = $this->tempManager->getTemporaryFile(); | ||
imageinterlace($outputImage, true); | ||
// Keep jpeg images encoded as jpeg | ||
if (str_contains($detectedMimeType, 'image/jpeg')) { | ||
if (!imagejpeg($outputImage, $newTmpFile, 90)) { | ||
throw new \Exception('Could not recompress background image as JPEG'); | ||
} | ||
} else { | ||
if (!imagepng($outputImage, $newTmpFile, 8)) { | ||
throw new \Exception('Could not recompress background image as PNG'); | ||
} | ||
} | ||
} | ||
$tmpFile = $newTmpFile; | ||
imagedestroy($outputImage); | ||
} catch (\Exception $e) { | ||
if (is_resource($outputImage) || $outputImage instanceof \GdImage) { | ||
$tmpFile = $newTmpFile; | ||
imagedestroy($outputImage); | ||
} | ||
} catch (\Exception $e) { | ||
if (isset($outputImage) && is_resource($outputImage) || $outputImage instanceof \GdImage) { | ||
imagedestroy($outputImage); | ||
} | ||
|
||
$this->logger->debug($e->getMessage()); | ||
$this->logger->debug($e->getMessage()); | ||
} | ||
} | ||
|
||
// For background images we need to announce it | ||
$this->backgroundService->setGlobalBackground($tmpFile); | ||
} | ||
|
||
$target->putContent(file_get_contents($tmpFile)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.