Files
Jump/jumpapp/background-css.php
2022-06-30 11:26:28 +01:00

32 lines
1.1 KiB
PHP

<?php
/**
* Generate dynamic CSS for randomising the background image.
*
* @author Dale Davies <dale@daledavies.co.uk>
* @license MIT
*/
// Provided by composer for psr-4 style autoloading.
require __DIR__ .'/vendor/autoload.php';
$config = new Jump\Config();
$blur = floor((int)$config->get('bgblur', false) / 100 * 15);
$brightness = (int)$config->get('bgbright', false) ? (int)$config->get('bgbright', false) / 100 : 1;
$bgurlstring = '';
// Use unsplash API for background images if provided, otherwise use altbgprovider.
// If none of the above have been provided then fall back to local image.
if ($config->get('unsplashapikey', false) == null) {
if ($config->get('altbgprovider', false) != null) {
$backgroundimageurl = $config->get('altbgprovider', false);
} else {
$backgroundimageurl = (new Jump\Background($config))->get_random_background_file();
}
$bgurlstring = 'background-image: url("'.$backgroundimageurl.'");';
}
header('Content-Type: text/css');
echo '.background {'.$bgurlstring.'filter: brightness('.$brightness.') blur('.$blur.'px);}';