'Add or replace a subreddit image, custom header logo, custom mobile
icon, or custom mobile banner.
* If the `upload_type` value is `img`, an image for use in the
subreddit stylesheet is uploaded with the name specified in `name`.
* If the `upload_type` value is `header` then the image uploaded will
be the subreddit\'s new logo and `name` will be ignored.
* If the `upload_type` value is `icon` then the image uploaded will be
the subreddit\'s new mobile icon and `name` will be ignored.
* If the `upload_type` value is `banner` then the image uploaded will
be the subreddit\'s new mobile banner and `name` will be ignored.
For backwards compatibility, if `upload_type` is not specified, the
`header` field will be used instead:
* If the `header` field has value `0`, then `upload_type` is `img`.
* If the `header` field has value `1`, then `upload_type` is `header`.
The `img_type` field specifies whether to store the uploaded image as a
PNG or JPEG.
Subreddits have a limited number of images that can be in use at any
given time. If no image with the specified name already exists, one of
the slots will be consumed.
If an image with the specified name already exists, it will be
replaced.  This does not affect the stylesheet immediately, but will
take effect the next time the stylesheet is saved.
See also: [/api/delete_sr_img](#POST_api_delete_sr_img),
[/api/delete_sr_header](#POST_api_delete_sr_header),
[/api/delete_sr_icon](#POST_api_delete_sr_icon), and
[/api/delete_sr_banner](#POST_api_delete_sr_banner).'

@require_oauth2_scope('modconfig')
@validate(VSrModerator(perms='config'), VModhash(), file=VUploadLength('file', max_length=(1024 * 500)), name=VCssName('name'), img_type=VImageType('img_type'), form_id=VLength('formid', max_length=100, docs={'formid': '(optional)    can    be    ignored'}), upload_type=VOneOf('upload_type', ('img', 'header', 'icon', 'banner')), header=VInt('header', max=1, min=0))
@api_doc(api_section.subreddits, uses_site=True)
def POST_upload_sr_img(self, file, header, name, form_id, img_type, upload_type=None):

    if c.site.quarantine:
        abort(403)
    errors = dict(BAD_CSS_NAME='', IMAGE_ERROR='')
    if (upload_type is None):
        upload_type = ('header' if header else 'img')
    if ((upload_type == 'img') and (not name)):
        errors['BAD_CSS_NAME'] = _('bad    image    name')
    if ((upload_type == 'img') and (not c.user_is_admin)):
        image_count = wiki.ImagesByWikiPage.get_image_count(c.site, 'config/stylesheet')
        if (image_count >= g.max_sr_images):
            errors['IMAGE_ERROR'] = (_('too    many    images    (you    only    get    %d)') % g.max_sr_images)
    try:
        size = str_to_image(file).size
    except (IOError, TypeError):
        errors['IMAGE_ERROR'] = _('Invalid    image    or    general    image    error')
    else:
        if (upload_type == 'icon'):
            if (size != Subreddit.ICON_EXACT_SIZE):
                errors['IMAGE_ERROR'] = (_('must    be    %dx%d    pixels') % Subreddit.ICON_EXACT_SIZE)
        elif (upload_type == 'banner'):
            aspect_ratio = (float(size[0]) / size[1])
            if (abs((Subreddit.BANNER_ASPECT_RATIO - aspect_ratio)) > 0.01):
                errors['IMAGE_ERROR'] = _('10:3    aspect    ratio    required')
            elif (size > Subreddit.BANNER_MAX_SIZE):
                errors['IMAGE_ERROR'] = (_('max    %dx%d    pixels') % Subreddit.BANNER_MAX_SIZE)
            elif (size < Subreddit.BANNER_MIN_SIZE):
                errors['IMAGE_ERROR'] = (_('min    %dx%d    pixels') % Subreddit.BANNER_MIN_SIZE)
    if any(errors.values()):
        return UploadedImage('', '', '', errors=errors, form_id=form_id).render()
    else:
        try:
            new_url = media.upload_media(file, file_type=('.' + img_type))
        except Exception as e:
            g.log.warning('error    uploading    subreddit    image:    %s', e)
            errors['IMAGE_ERROR'] = _('Invalid    image    or    general    image    error')
            return UploadedImage('', '', '', errors=errors, form_id=form_id).render()
        details_text = 'upload_image'
        if (not (upload_type == 'img')):
            details_text = ('upload_image_%s' % upload_type)
        VNotInTimeout().run(action_name='editsettings', details_text=details_text, target=c.site)
        if (upload_type == 'img'):
            wiki.ImagesByWikiPage.add_image(c.site, 'config/stylesheet', name, new_url)
            kw = dict(details='upload_image', description=name)
        elif (upload_type == 'header'):
            c.site.header = new_url
            c.site.header_size = size
            c.site._commit()
            kw = dict(details='upload_image_header')
        elif (upload_type == 'icon'):
            c.site.icon_img = new_url
            c.site.icon_size = size
            c.site._commit()
            kw = dict(details='upload_image_icon')
        elif (upload_type == 'banner'):
            c.site.banner_img = new_url
            c.site.banner_size = size
            c.site._commit()
            kw = dict(details='upload_image_banner')
        ModAction.create(c.site, c.user, action='editsettings', **kw)
        return UploadedImage(_('saved'), new_url, name, errors=errors, form_id=form_id).render()
