How to get file from managed_filed in drupal 8 generate image style and use as background image for a div I had created a form filed to upload an image on a themes settings page like this

$form ['ad_tv']['tv_adbackground'] = array(
    '#type'     =&gt; 'managed_file',
    '#title'    =&gt; t('Hintergrundbild'),
    '#required' =&gt; FALSE,
    '#upload_location' =&gt; file_default_scheme() . '://theme/backgrounds/',
    '#default_value' =&gt; theme_get_setting('tv_adbackground'),
    '#upload_validators' =&gt; array(
      'file_validate_extensions' =&gt; array('gif png jpg jpeg'),

),


Now I like to know 

with preprocess function to use in mytheme.theme to make sure the file gets overwritten, if a new one is uploaded.
how to add the path of the uploaded file or its image style to add the path as background image to a div with a css id called advertisement

I hape that this is not to much for one question. I am new to drupal 8. So any help will be welcome-

thank you.
Untested, but you should be able to do this:

$style = Drupal\image\Entity\ImageStyle::load(IMAGESTYLENAME);

$url = $style-&gt;buildUrl(theme_get_setting('tv_adbackground'));

$element['background'] = [
  '#prefix' =&gt; '&lt;div style="background-image:url(' . $url . ')"&gt;',
  '#suffix' =&gt; '&lt;/div&gt;',
  // Force rendering of this element
  '#markup' =&gt; '',
];


You'll need to change IMAGESTYLENAME to the actual image style you want to apply.