Skip to content
Permalink
Browse files

fix: Correct processing of embedded image type. (#33)

* fix: Correct processing of embedded image type.
* chore: Fixed flake8 warnings.
  • Loading branch information...
sergey48k committed Jan 25, 2019
1 parent ccf19ad commit ce4147b7ad546bc86f2f5ef1daac2faee73de648
Showing with 7 additions and 5 deletions.
  1. +5 −4 fame/avatar.py
  2. +2 −1 fame/glory.py
@@ -146,16 +146,17 @@ def _embed_face(self):
Browsers don't display referenced images in <img>.
"""
face_url = self.face_image.get('{http://www.w3.org/1999/xlink}href')
BASE64_HEADER = 'data:image/jpeg;base64,'
if face_url.startswith(BASE64_HEADER):
if face_url.startswith('data:image/'):
return
if not face_url.startswith('http'):
# Relative path.
face_url = 'https://sourcerer.io' + face_url

data = urlopen(face_url).read()
response = urlopen(face_url)
content_type = response.headers.get_content_type()
data = response.read()
encoded = base64.b64encode(data).decode()
data_url = BASE64_HEADER + encoded
data_url = 'data:%s;base64,%s' % (content_type, encoded)
self.face_image.set('{http://www.w3.org/1999/xlink}href', data_url)
print('i Embedded JPEG %s' % face_url)

@@ -164,7 +164,8 @@ def _get_sourcerer_mapping_url(self, github_usernames):
self.sourcerer_api_origin, ','.join(github_usernames))

def _get_sourcerer_avatar_url(self, sourcerer_username):
return '%s/assets/avatar/%s' % (self.sourcerer_origin, sourcerer_username)
return '%s/assets/avatar/%s' % (self.sourcerer_origin,
sourcerer_username)

def _save_svg(self, num, svg):
image_path = self._get_image_file_path(num, temp=True)

0 comments on commit ce4147b

Please sign in to comment.
You can’t perform that action at this time.