code: def upload_image(self, subreddit, image_path, name=None,
                       header=False, upload_as=None):
          
          if name and header:
              raise TypeError('Both name and header cannot be set.')
          if upload_as not in (None, 'png', 'jpg'):
              raise TypeError("upload_as must be 'jpg', 'png', or None.")
          with open(image_path, 'rb') as image:
              image_type = upload_as or _image_type(image)
              data = {'r': six.text_type(subreddit), 'img_type': image_type}
              if header:
                  data['header'] = 1
              else:
                  if not name:
                      name = os.path.splitext(os.path.basename(image.name))[0]
                  data['name'] = name
  
              response = json.loads(self._request(
                  self.config['upload_image'], data=data, files={'file': image},
                  method=to_native_string('POST'), retry_on_error=False))
  
          if response['errors']:
              raise errors.APIException(response['errors'], None)
          return response['img_src']
docs: Upload an image to the subreddit.
  
          :param image_path: A path to the jpg or png image you want to upload.
          :param name: The name to provide the image. When None the name will be
              filename less any extension.
          :param header: When True, upload the image as the subreddit header.
          :param upload_as: Must be `'jpg'`, `'png'` or `None`. When None, this
              will match the format of the image itself. In all cases where both
              this value and the image format is not png, reddit will also
              convert  the image mode to RGBA. reddit optimizes the image
              according to this value.
          :returns: A link to the uploaded image. Raises an exception otherwise.