apps/theming/lib/Controller/ThemingController.php
/**
	 * Update the logos and background image
	 *
	 * @return DataResponse
	 */
Update the logos and background image
@return DataResponse
Update the logos and background image @return DataResponse
public function updateLogo() {
		$backgroundColor = $this->request->getParam('backgroundColor', false);
		if($backgroundColor) {
			$this->themingDefaults->set('backgroundMime', 'backgroundColor');
			return new DataResponse(
				[
					'data' =>
						[
							'name' => 'backgroundColor',
							'message' => $this->l10n->t('Saved')
						],
					'status' => 'success'
				]
			);
		}
		$newLogo = $this->request->getUploadedFile('uploadlogo');
		$newBackgroundLogo = $this->request->getUploadedFile('upload-login-background');
		if (empty($newLogo) && empty($newBackgroundLogo)) {
			return new DataResponse(
				[
					'data' => [
						'message' => $this->l10n->t('No file uploaded')
					]
				],
				Http::STATUS_UNPROCESSABLE_ENTITY
			);
		}
		$name = '';
		try {
			$folder = $this->appData->getFolder('images');
		} catch (NotFoundException $e) {
			$folder = $this->appData->newFolder('images');
		}
		if (!empty($newLogo)) {
			$target = $folder->newFile('logo');
			$target->putContent(file_get_contents($newLogo['tmp_name'], 'r'));
			$this->themingDefaults->set('logoMime', $newLogo['type']);
			$name = $newLogo['name'];
		}
		if (!empty($newBackgroundLogo)) {
			$target = $folder->newFile('background');
			$image = @imagecreatefromstring(file_get_contents($newBackgroundLogo['tmp_name'], 'r'));
			if ($image === false) {
				return new DataResponse(
					[
						'data' => [
							'message' => $this->l10n->t('Unsupported image type'),
						],
						'status' => 'failure',
					],
					Http::STATUS_UNPROCESSABLE_ENTITY
				);
			}
			$tmpFile = $this->tempManager->getTemporaryFile();
			if (function_exists('imagescale')) {
				$newHeight = imagesy($image) / (imagesx($image) / 1920);
				$image = imagescale($image, 1920, $newHeight);
			}
			imageinterlace($image, 1);
			imagejpeg($image, $tmpFile, 75);
			imagedestroy($image);
			$target->putContent(file_get_contents($tmpFile, 'r'));
			$this->themingDefaults->set('backgroundMime', $newBackgroundLogo['type']);
			$name = $newBackgroundLogo['name'];
		}
		return new DataResponse(
			[
				'data' =>
					[
						'name' => $name,
						'message' => $this->l10n->t('Saved')
					],
				'status' => 'success'
			]
		);
	}
public function updateLogo ( ) { $ backgroundColor = $ this -> request -> getParam ( 'backgroundColor' , false ) ; if ( $ backgroundColor ) { $ this -> themingDefaults -> set ( 'backgroundMime' , 'backgroundColor' ) ; return new DataResponse ( [ 'data' => [ 'name' => 'backgroundColor' , 'message' => $ this -> l10n -> t ( 'Saved' ) ] , 'status' => 'success' ] ) ; } $ newLogo = $ this -> request -> getUploadedFile ( 'uploadlogo' ) ; $ newBackgroundLogo = $ this -> request -> getUploadedFile ( 'upload-login-background' ) ; if ( empty ( $ newLogo ) && empty ( $ newBackgroundLogo ) ) { return new DataResponse ( [ 'data' => [ 'message' => $ this -> l10n -> t ( 'No file uploaded' ) ] ] , Http :: STATUS_UNPROCESSABLE_ENTITY ) ; } $ name = '' ; try { $ folder = $ this -> appData -> getFolder ( 'images' ) ; } catch ( NotFoundException $ e ) { $ folder = $ this -> appData -> newFolder ( 'images' ) ; } if ( ! empty ( $ newLogo ) ) { $ target = $ folder -> newFile ( 'logo' ) ; $ target -> putContent ( file_get_contents ( $ newLogo [ 'tmp_name' ] , 'r' ) ) ; $ this -> themingDefaults -> set ( 'logoMime' , $ newLogo [ 'type' ] ) ; $ name = $ newLogo [ 'name' ] ; } if ( ! empty ( $ newBackgroundLogo ) ) { $ target = $ folder -> newFile ( 'background' ) ; $ image = @ imagecreatefromstring ( file_get_contents ( $ newBackgroundLogo [ 'tmp_name' ] , 'r' ) ) ; if ( $ image === false ) { return new DataResponse ( [ 'data' => [ 'message' => $ this -> l10n -> t ( 'Unsupported image type' ) , ] , 'status' => 'failure' , ] , Http :: STATUS_UNPROCESSABLE_ENTITY ) ; } $ tmpFile = $ this -> tempManager -> getTemporaryFile ( ) ; if ( function_exists ( 'imagescale' ) ) { $ newHeight = imagesy ( $ image ) / ( imagesx ( $ image ) / 1920 ) ; $ image = imagescale ( $ image , 1920 , $ newHeight ) ; } imageinterlace ( $ image , 1 ) ; imagejpeg ( $ image , $ tmpFile , 75 ) ; imagedestroy ( $ image ) ; $ target -> putContent ( file_get_contents ( $ tmpFile , 'r' ) ) ; $ this -> themingDefaults -> set ( 'backgroundMime' , $ newBackgroundLogo [ 'type' ] ) ; $ name = $ newBackgroundLogo [ 'name' ] ; } return new DataResponse ( [ 'data' => [ 'name' => $ name , 'message' => $ this -> l10n -> t ( 'Saved' ) ] , 'status' => 'success' ] ) ; }
Update the logos and background image
 @return DataResponse
Update the logos and background image @return DataResponse
// Optimize the image since some people may upload images that will be // either to big or are not progressive rendering. // FIXME: Once PHP 5.5.0 is a requirement the above check can be removed // Workaround for https://bugs.php.net/bug.php?id=65171